User Guide
78 Handling Component Events
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);
Using the on() event handler
You can assign the on() event handler to a component instance, just as you would assign a
handler to a button or movie clip. An
on() event handler can be useful for simple testing, but
for all applications, use event listeners, instead. For more information, see “Using listeners to
handle events” on page 64.
When you use the keyword
this within an on() handler attached directly to a component
(assigned to the component instance in the Actions panel),
this refers to the component
instance. For example, the following code, attached directly to the Button component
instance
myButton, displays “_level0.myButton” in the Output panel:
on(click){
trace(this);
}