You need to this when you build a Flash app based on MVC. Actually, this is an example of the Observer Pattern without creating the interface classes. You can make a package with a class that extends the EventDispatcher, then you can make another class(es) that listen for it to change:
package
{
import flash.events.*;
public class VariableHolder extends EventDispatcher
{
private var yourVariable:String;
public function getYourVariable():String
{
return yourVariable;
}
public function setYourVariable(newOne:String):void
{
yourVariable = newOne;
this.update();
}
protected function update():void
{
dispatchEvent(new Event(Event.CHANGE));
}
}
}
Then the class that listens for it
package
{
import flash.events.*;
public class ListensForEvent
{
private var variableHolder:VariableHolder;
private var theOneInTheHolder:String;
//this will take the VariableHolder as a parameter when instantiated
public function ListensForEvent(vHolder:VariableHolder)
{
this.variableHolder = vHolder;
}
public function update(event:Event = null):void
{
theOneInTheHolder = variableHolder.getYourVariable();
trace(theOneInTheHolder);
}
}
}
to make it all work put this on the timeline:
import VariableHolder;
import ListensForEvent;
var theHolder:VariableHolder = new VariableHolder();
var listener1:ListensForEvent = new ListensForEvent(theHolder);
theHolder.addEventListener(Event.CHANGE, listener1.update);
var listener2:ListensForEvent = new ListensForEvent(theHolder);
theHolder.addEventListener(Event.CHANGE, listener2.update);
theHolder.setYourVariable('new Variable');
//this should have:
//new Variable
//new Variable
//in the output
modEdit: please edit your original post instead of double or triple posting