EasyManua.ls Logo

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT - Scope of the This Keyword

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT
816 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
90 Chapter 4: 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 youre using,
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
myClip itself.
// onPress() event handler attached to _level0.myClip:
myClip.onPress = function () {
trace(this); // displays '_level0.myClip'
}
Within an on() handler attached to a movie clip
, this refers to the movie clip to which the
on() handler is attached.
// Attached to movie clip named 'myClip'
on(press) {
trace(this); displays '_level0.myClip'
}
Within an on() handler attached to a button
, this refers to the Timeline that contains the
button.
// Attached to button on main Timeline
on(press) {
trace(this); // displays '_level0'
}

Table of Contents

Related product manuals