You can register multiple listeners to a single component instance, but you must use a separate call
to
addEventListener()
component instances, but you must use a separate call to
For example, the following code defines one listener object and assigns it to two Button
component instances, whose
lo = new Object();
lo.click = function(evt){
trace(evt.target.label + " clicked");
}
button1.addEventListener("click", lo);
button2.addEventListener("click", lo);
Execution order is not guaranteed. You cannot expect one listener to be called before another.
An event object is passed to the listener as a parameter. The event object has properties that
contain information about the event that occurred. You can use the event object inside the
listener callback function to access information about the type of event that occurred and which
instance broadcast the event. In the example above, the event object is
identifier as the event object name), and it is used in the
instance was clicked. For more information, see
Example
The following example defines a listener object,
for the
event. It then calls
click
with the component instance
myListener = new Object();
myListener.click = function(evt){
trace(evt.type + " triggered");
}
myButton.addEventListener("click", myListener);
To test this code, place a Button component on the Stage with the instance name
place this code in Frame 1.
EventDispatcher.dispatchEvent()
Availability
Flash Player 6 (6.0 79.0).
Edition
Flash MX 2004 and Flash MX Professional 2004.
Usage
dispatchEvent(eventObject)
for each listener. Also, you can register one listener to multiple
properties are
label
addEventListener()
.
myButton
addEventListener()
and
button1
button2
statements to determine which button
if
"About the event object" on page
, and defines the callback function
myListener
to register the
myListener
for each instance.
, respectively:
(you can use any
evt
66.
listener object
, and
myButton
EventDispatcher class
417
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?