EasyManua.ls Logo

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT - Page 89

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...
Event handler scope 89
For instance, the following on() event handler will produce different results depending on
whether its attached to a movie clip or button object. In the first case, the
play() function call
starts the playback head of the Timeline that contains the button; in the second case, the
play()
function call starts the Timeline of the movie clip to which the handler is attached.
// Attached to button
on(press) {
play(); // plays parent Timeline
}
// Attached to movie clip
on(press) {
play(); // plays movie clip’s Timeline
}
That is, when attached to a button object, the play() method call applies to the Timeline that
contains the button—that is, the buttons parent Timeline. But when the same handler is attached
to a movie clip object, then the
play() applies to the movie clip that bears the handler.
Within an event handler or event listener function definition, the same
play() function would
apply to the Timeline that contains the function definition. For example, suppose the following
MovieClip.onPress event handler function were declared on the Timeline that contains the
movie clip instance
myMovieClip.
// Function defined on movie clip Timeline:
myMovieClip.onPress = function () {
play(); // plays Timeline that contains the function definition
}
If you want to play the movie clip that defines the onPress event handler, then you have to refer
explicitly to that clip using the
this keyword, as follows:
myMovieClip.onPress = function () {
this,play(); // plays Timeline of clip that defines the onPress handler
}

Table of Contents

Related product manuals