//observer //////////////////////////////////////////////////// //make sure to import EventDispatcher import mx.events.EventDispatcher; //what we will watch for changes theObserved = true; //create an ‘observer’ //this will watch ‘theObserved’ and tell anyone interested it has changed. observer = {}; //add eventDispatcher methods to ‘observer’ mx.events.EventDispatcher.initialize(observer); //add a watch to dispatch an event from observer watch("theObserved", function (a, b, c) { observer.dispatchEvent({type:"change", name:a, newValue:c}); }); //create a listener //the ‘observer’ will tell this listener when something happens listener = {}; //create an event to be called by the ‘observer’ listener.change = function(eo) { trace('The observer said "'+eo.name+'" changed to '+eo.newValue); }; //add the listener to the observer observer.addEventListener('change', listener); //change the value of ‘theObserved’ to test theObserved = false; theObserved = true; theObserved = "OOOOH"; theObserved = "AAAAH"; /* trace The observer said "theObserved" changed to false The observer said "theObserved" changed to true The observer said "theObserved" changed to OOOOH The observer said "theObserved" changed to AAAAH */