ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Example: Adding States and Identifying Users | 301

Be sure to save theBugleSubscribe.asin the same folder as the other files in the class.


Then, create a new Flash document, and type inBugleSubscribein the Document


class window. When you test the application, you should see the following output:


*|*Concrete Subject*|*
Larry has subscribed
Mo has subscribed
Curly has subscribed
Shemp has subscribed
Larry sees that Faster Computer Invented is interesting, and learns
that Home Team Wins.
Whoaa!, the stock market is at 3234.54 and The Mad Duck is showing
at the Bijou.
Mo sees that Faster Computer Invented is interesting, and learns
that Home Team Wins.
Whoaa!, the stock market is at 3234.54 and The Mad Duck is showing
at the Bijou.
Curly sees that Faster Computer Invented is interesting, and learns
that Home Team Wins.
Whoaa!, the stock market is at 3234.54 and The Mad Duck is showing
at the Bijou.
Shemp sees that Faster Computer Invented is interesting, and learns
that Home Team Wins.
Whoaa!, the stock market is at 3234.54 and The Mad Duck is showing
at the Bijou.

** Larry and Shemp have unsubscribed **

Mo is already a subscriber.

Mo sees that Memory Prices Down is interesting, and learns that Game
Rained Out.

//Set State #1
bigNews.setType("Computer Invented","Home Team Wins",
3234.54," Mad Duck");


//Unsubscribe 2 Observers and attempt to re-subscribe
current subscriber
trace("\n Larry and Shemp have unsubscribed \n");
bigNews.unsubscribeObserver(larry);
bigNews.unsubscribeObserver(shemp);


//Attempt re-subscribe
bigNews.subscribeObserver(mo);


//Set State #2
bigNews.setType("Memory Prices Down","Game Rained Out",
2987.98," Bad Bug");
}
}
}


Example 8-14. BugleSubscribe.as (continued)

Free download pdf