Simple question..I was wondering when you guys extends EventDispatcher in your class. It seems to me that as long as we have import event package, we can dispatchEvent without problems….I saw sometime people extends EventDispatcher in their class…not sure why…anyone care to explain? Thanks a million…
Simple question..I was wondering when you guys extends EventDispatcher in your class. It seems
Share
I think you might be confusing the fact that many objects in AS3 extend EventDispatcher higher in the inheritance tree with only needing to import the flash.events package in order to dispatch events. For instance many DisplayObject classes extend the EventDispatcher. Here are a couple of examples:
Typically I will extend EventDispatcher any time I am working with a custom class that just needs to communicate to objects outside of it’s scope that some internal property has changed or that some function is occuring. Here is an example:
Sometimes it is “important” to keep the internal details of an object read only. In the case of the above example, when the
run()method is called, theClockclass performs some internal logic and then dispatches an event indicating that something has changed. Any class that is listening for that event can then call the publicgetTick()method to find out the value of_tick. This hides the implementation and protects the_tickvariable from being changed by outside classes and at the same time provides an interface through which theClockcan be read.