User Guide

66 Chapter 4: Handling Component Events
// from the chb_onClick function
var i:Number = 10
function onLoad() {
myCheckBox_chb.addEventListener("click", Delegate.create(this,
chb_onClick));
}
function chb_onClick(eventObj:Object) {
// Sends 10 to the Output panel
// because the function is scoped to
// the Cart instance
trace(i);
}
}
About the event object
The event object is an instance of the ActionScript Object class; it has the following properties
that contain information about an event.
When an event has additional properties, they are listed in the event’s entry in the Components
Dictionary.
The event object is automatically generated when an event is triggered and passed to the listener
object’s callback function or the listener function.
You can use the event object inside the function to access the name of the event that was
broadcast, or the instance name of the component that broadcast the event. From the instance
name, you can access other component properties. For example, the following code uses the
target property of the evtObj event object to access the label property of the myButton
instance and sends the value to the Output panel:
var myButton:mx.controls.Button;
var listener:Object;
listener = new Object();
listener.click = function(evtObj){
trace("The " + evtObj.target.label + " button was clicked");
}
myButton.addEventListener("click", listener);
Property Description
type
A string indicating the name of the event.
target
A reference to the component instance broadcasting the event.