Chapter 21: Eventdispatcher Class; Event Objects - MACROMEDIA FLASH 8-COMPONENTS LANGUAGE Reference

Components language reference
Table of Contents

Advertisement

2 1
CHAPTER 21
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
method to register a listener with a component
EventDispatcher.addEventListener()
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
property of the
event object to access the
target
evtObj
label
property of the
instance and send the value to the Output panel:
myButton
listener = new Object();
listener.click = function(evtObj){
trace("The " + evtObj.target.label + " button was clicked");
}
myButton.addEventListener("click", listener);
499

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-COMPONENTS LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents