User Guide
EventDispatcher class 415
EventDispatcher class
Events let your application know when the user has interacted with a component, and when
important changes have occurred in the appearance or life cycle of a component—such as its
creation, destruction, or resizing.
The methods of the EventDispatcher class let you add and remove event listeners so that your
code can react to events appropriately. For example, you use the
EventDispatcher.addEventListener() method to register a listener with a component
instance. The listener is invoked when a component’s event is triggered.
If you want to write a custom object that emits events that aren’t related to the user interface,
EventDispatcher is smaller and faster to use as a mix-in for UIComponent than
UIEventDispatcher.
Event objects
An event object is passed to a listener as a parameter. The event object is an ActionScript object
that has properties that contain information about the event that occurred. You can use the event
object inside the listener callback function to access the name of the event that was broadcast, or
the instance name of the component that broadcast the event. For example, the following code
uses the
target property of the evtObj event object to access the label property of the
myButton instance and send the value to the Output panel:
listener = new Object();
listener.click = function(evtObj){
trace("The " + evtObj.target.label + " button was clicked");
}
myButton.addEventListener("click", listener);
Some event object properties are defined in the W3C specification (www.w3.org/TR/DOM-
Level-3-Events/events.html) but aren’t implemented in version 2 of the Macromedia Component
Architecture. Every version 2 event object has the properties listed in the table below. Some events
have additional properties defined, and if so, the properties are listed in the event’s entry.
EventDispatcher class (API)
ActionScript Class Name mx.events.EventDispatcher
Property Description
type
A string indicating the name of the event.
target
A reference to the component instance broadcasting the event.
CHAPTER 6
Components Dictionary