MACROMEDIA FLASH MX 2004-USING COMPONENTS Use Manual page 60

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

Advertisement

function handleEvent(evt){
// check if the event was a click
if (evt.type == "click"){
// do something if the event was click
} else if (evt.type == "change"){
// do something else if the event was change
}
};
// register the listener object to
// two different component instances
// because the function is defined on
// "this" object, the listener is this.
instance.addEventListener("click", this);
instance2.addEventListener("change", this);
Using listener functions
Unlike the
handleEvent
of having the
if
the
event and
change
myList.addEventListener("change", myChangeHandler);
myList.addEventListener("scroll", myScrollHandler);
To use a listener function, you must first define a function:
function myFunction:Function(evtObj:Object){
// your code here
}
Tip: The
parameter is an object that is automatically generated when an event is triggered and
evtObj
passed to the function. The event object has properties that contain information about the event. For
details, see
"About the event object" on page
Then you call the
the event. The
addEventListener()
of the event and a reference to the function.
componentInstance.addEventListener("eventName", myFunction);
You can call
addEventListener()
component from the EventDispatcher class. For more information, see
EventDispatcher.addEventListener()
For information about the events a component broadcasts, see each component's entry in
Chapter 6, "Components Dictionary," on page
To register a listener object in a Flash (FLA) file:
In Flash, select File > New and create a new Flash document.
1.
Drag a List component to the Stage from the Components panel.
2.
In the Property inspector, enter the instance name myList.
3.
60
Chapter 4: Handling Component Events
syntax, several listener functions can handle different events. So instead
and
checks in
else if
myScrollHandler
addEventListener()
method takes two parameters: a string indicating the name
from any component instance; it is mixed in to every
, you can just define
myHandler
for the
event and register them, as shown here:
scroll
66.
method from the component instance that broadcasts
on page
416.
91.
for
myChangeHandler

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