I want the stage to react every time some changes are made to certain objects. Is there a way to write custom Event? I could of course modify this object, but I would like to know if there is any more OOP way to do it. And events ARE OOP, ain’t they?
I want the stage to react every time some changes are made to certain
Share
Lets say you have a property
countin some class. Easiest way is to generate setter and getter for this property and inside the setter to dispatch some custom event.This is the custom event class:
Note that if you need the value of the property and don’t have reference to the object itself, you can create a data-object event. In order for this kind of custom event to work properly you need to override the clone method, which is used every time the event is re-dispatched.
If you are looking for more advanced way of “observing” something is by using some custom code, e.g.
http://code.google.com/p/flit/source/browse/trunk/flit/src/obecto/utility/observe/Observe.as?r=190
In either way you must decide whether you want to modify your class by adding a dispatcher (if your class is not a EventDispatcher subclass) and dispatch an event or use some other techniques. Another way is to make the property
[Bindable]and use a binding between your property and some function to watch if something changes.