User Guide
180 Chapter 6: 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 MovieClip.gotoAndPlay() and
MovieClip.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 where you want to jump.
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
instance 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 applies.
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 start or stop 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() or gotoAndPlay().
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) {