Flash CS3 Documentation |
|||
| Using ActionScript 2.0 Components > Handling Component Events > 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.
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);
}
For example, drag a Button component to the Stage.
on() handler to the Actions panel in the format:
on(event){
//your statements go here
}
For example:
on(click){
trace(this);
}
Flash runs the code inside the on() handler when the event for the on() handler occurs (in this case, a button click).
Flash CS3