Using ActionScript 2.0 Components |
|
|
|
| Handling Component Events > Using listeners to handle events > Using the handleEvent callback function | |||
You can also use listener objects that support a handleEvent function. Regardless of the name of the event that is broadcast, the listener object's handleEvent method is called. You must use an if..else or a switch statement to handle multiple events. For example, the following code uses an if..else statement to handle the click and change events:
// define the handleEvent function
// pass it evt as the event object parameter
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);
|
|
|
|