When using EventDispatcher.dispatchEvent(), you pass in an Event instance that is specific to the event being dispatched. The type of event dispatched is defined within the Event instance used. For example, dispatching an “enterFrame” event would mean using dispatchEvent with an Event instance instantiated with the type “enterFrame”.
When an event handler is executed as a result of this event, that event object is passed into the function as a single argument. Properties from that event can then be extracted to learn more about the event that occured. For example, the type property from the Event class tells which event was dispatched.
dispatchEvent(new Event(“enterFrame”));
…
private function eventHandler(event:Event):void {
trace(event.type); // “enterFrame”
}
Though event types are strings, all common Flash events are available in Flash through static constants of the Event classes. The “enterFrame” event type, for example, is accessible using Event.ENTER_FRAME. Mouse events are within the MouseEvent class. Click events, for example, are MouseEvent.CLICK. These constants are prefered over their string representations.
dispatchEvent(new Event(Event.ENTER_FRAME));
When making your custom Events, you can use the Event object with a custom type or alternatively, extend the Event class creating a new kind of Event instance to be used with your events.
You might also like
| EventDispatcher in AS3 ActionScript 3 uses the EventDispatcher (flash.events.EventDispatcher) class for all event handling. This class... | describeType in AS3 that's beautiful.. so much better than typeof.. Though I might also add (if I may), if you want some extremely... | Flash Optimization – Activate & Deactivate Events Flash optimization is becoming increasing important & with alternative development tools that developers... | Render Event in AS3 ActionScript has long since relied on the enterFrame (onEnterFrame) event for time-based actions, especially animation... |






