// your code here
};
Tip: The
parameter is an object that is automatically generated when an event is triggered and
evtObj
passed to the callback function. The event object has properties that contain information about the
event. For details, see
Finally, you call the
the event. The
addEventListener()
of the event and a reference to the listener object.
componentInstance.addEventListener("eventName", listenerObject);
Here is the whole code segment, which you can copy and paste. Be sure to replace any code in
italics with actual values; you can use
but you must change
var listenerObject:Object = new Object();
listenerObject.eventName = function(evtObj:Object){
// code placed here executes
// when the event is triggered
};
componentInstance.addEventListener("eventName", listenerObject);
The following code segment uses the
function eventName(evtObj:Object){
// code placed here executes
// when the event is triggered
}
componentInstance.addEventListener("eventName", this);
You can call
addEventListener()
component from the EventDispatcher class. (A "mix-in" is a class that provides specific features
that augment the behavior of another class.) For more information, see
EventDispatcher.addEventListener()
For information about the events a component broadcasts, see the component's entry in
Chapter 6, "Components Dictionary," on page
are listed in the Button component section (or Help > Using Components > Components
Dictionary > Button component > Button class > Event summary for the Button class).
To register a listener object in a Flash (FLA) file:
In Flash, select File > New and create a new Flash document.
1.
Drag a Button component to the Stage from the Components panel.
2.
In the Property inspector, enter the instance name myButton.
3.
Drag a TextInput component to the Stage from the Components panel.
4.
In the Property inspector, enter the instance name myText.
5.
Select Frame 1 in the Timeline.
6.
Select Window > Development Panels > Actions.
7.
58
Chapter 4: Handling Component Events
"About the event object" on page
addEventListener()
method takes two parameters: a string indicating the name
listenerObject
to the name of the event.
eventName
this
from any component instance; it is mixed in to every
66.
method from the component instance that broadcasts
and
evtObj
keyword as the listener object:
on page
416.
91. For example, Button component events
or any other legal identifiers,
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?
Questions and answers