Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Handling Events > Scope of the this keyword | |||
The this keyword refers to the object in the currently executing scope. Depending on what type of event handler technique you use, this can refer to different objects.
Within an event handler or event listener function, this refers to the object that defines the event handler or event listener method. For example, in the following code, this refers to my_mc:
// onPress() event handler attached to main timeline:
my_mc.onPress = function () {
trace(this); // _level0.my_mc
}
Within an on() handler attached to a movie clip, this refers to the movie clip to which the on() handler is attached, as shown in the following code:
// Attached to movie clip named my_mc on main timeline
on (press) {
trace(this); // _level0.my_mc
}
Within an on() handler attached to a button, this refers to the timeline that contains the button, as shown in the following code:
// Attached to button on main timeline
on (press) {
trace(this); // _level0
}
|
|
|
|