Example: Adding States and Identifying Users | 299
for (var notify in this.observers)
{
observers[notify].update (news,sports,
stocks,entertainment);
var nowNews:String=" sees that "+
news + " is interesting,";
var nowSports:String = " and learns that " + sports;
var nowStocks:String=".\nWhoaa!,
the stock market is at " + stocks;
var nowEntertain:String=" and "+ entertainment +
" is showing at the Bijou.";
trace (observers[notify].subName + nowNews +
nowSports + nowStocks + nowEntertain);
}
}
//Add all necessary states
public function setType (news:String,sports:String,stocks:Number,
entertainment:String):void
{
this.news=news;
this.sports=sports;
this.stocks=stocks;
this.entertainment=entertainment;
notifyObserver ( );
}
}
}
Example 8-13. ConcreteObserver.as
package
{
//Concrete Observer
class ConcreteObserver implements Observer
{
//Store Additional States
private var news:String;
private var sports:String;
private var stocks:Number;
private var entertainment:String;
//Subscriber's ID
public var subName:String;
//Constructor Function
function ConcreteObserver(subName:String):void
{
trace(subName + " has subscribed");
this.subName=subName;
}
Example 8-12. ConcreteSubject.as (continued)