Event handler scope
89
For instance, the following
on()
event handler will produce different results depending on
whether it’s 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 button’s 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
}
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...