MACROMEDIA FLASH MX 2004-USING COMPONENTS Use Manual page 57

Using components
Hide thumbs Also See for FLASH MX 2004-USING COMPONENTS:
Table of Contents

Advertisement

To register a listener to a broadcaster, call the
broadcaster. Use the following syntax:
componentInstance.addEventListener("eventName", listenerObjectORFunction);
You can register multiple listeners to one component instance.
myButton.addEventListener("click", listener1);
myButton.addEventListener("click", listener2);
You can register one listener to multiple component instances.
myButton.addEventListener("click", listener1);
myButton2.addEventListener("click", listener1);
The handler function is passed an event object.
You can use the event object in the body of the function to retrieve information about the
event type, and the instance that broadcast the event. See
Using listener objects
To use a listener object, you can either use the
listener, use an object that already exists in your application, or create a new object.
Use
in most situations.
this
It's often easiest to use the current object (
components that need to react when the event is broadcast.
Use an existing object if it is convenient.
For example, in a Flash Form Application, you may want to use a form as a listener object if
that form contains the components that react to the event. Place the code on a frame of the
form's Timeline.
Use a new listener object if many components are broadcasting an event (for example, the
event) and you want only certain listener objects to respond.
click
If you use the
this
the syntax is as follows:
function eventName(evtObj:Object){
// your code here
};
If you want to use a new listener object, you must create the object, define a property with the
same name as the events, and assign the property to a callback function that executes when the
event is broadcast, as follows:
var listenerObject:Object = new Object();
listenerObject.eventName = function(evtObj:Object){
// your code here
};
If you want to use an existing object, use the same syntax as a new listener object, without
creating the new object, as shown here:
existingObject.eventName = function(evtObj:Object){
object, define a function with the same name as the event you want to handle;
addEventListener()
"About the event object" on page
keyword to specify the current object as the
this
) as a listener, because its scope contains the
this
Using listeners to handle events
method from the
66.
57

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx

Table of Contents