92
Chapter 5: Creating Interaction with ActionScript
Controlling SWF file playback
The following ActionScript functions let you control the playhead in the Timeline and load a new
web page into a browser window:
•
The
gotoAndPlay()
and
gotoAndStop()
functions send the playhead to a frame or scene.
These are global functions that you can call from any script. You can also use the
MovieClip.gotoAndPlay()
and
MovieClip.gotoAndStop()
methods to navigate the
Timeline of a specific movie clip object.
•
The
play()
and
stop()
actions play and stop movies.
•
The
getURL()
action jumps to a different URL.
Jumping to a frame or scene
To jump to a specific frame or scene in the SWF file, you can use the
gotoAndPlay()
and
gotoAndStop()
global functions or the equivalent
gotoAndPlay()
and
gotoAndStop()
methods of the MovieClip class. Each function or method lets you specify a frame to jump to in
the current scene. If your document contains multiple scenes, you can specify a scene and frame
to jump to.
The following example uses the global
gotoAndPlay()
function within a button object’s
onRelease
event handler to send the playhead of the Timeline that contains the button to
Frame 10.
jump_btn.onRelease = function () {
gotoAndPlay(10);
}
In the next example, the
MovieClip.gotoAndStop()
method sends the Timeline of a movie clip
named
categories_mc
to Frame 10 and stops. When you use the MovieClip methods
gotoAndPlay()
and
gotoAndStop(),
you must specify an instance to which the method.
jump_btn.onPress = function () {
categories_mc.gotoAndStop(10);
}
Playing and stopping movie clips
Unless instructed otherwise, after a SWF file starts, it plays through every frame in the Timeline.
You can stop or start a SWF file by using the
play()
and
stop()
global functions or the
equivalent MovieClip methods. For example, you can use
stop()
to stop a SWF file at the end of
a scene before proceeding to the next scene. After a SWF file stops, it must be explicitly started
again by calling
play()
.
You can use the
play()
and
stop()
functions or MovieClip methods to control the main
Timeline or the Timeline of any movie clip or loaded SWF file. The movie clip you want to
control must have an instance name and must be present in the Timeline.
The following
on(press)
handler attached to a button starts the playhead moving in the SWF
file or movie clip that contains the button object.
// Attached to a button instance
on(press) {
// Plays the Timeline that contains the button
play();
}
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...