Controlling SWF file playback 563
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);
};
In the final example, the global gotoAndStop() function is used to move the playhead to
Frame 1 of Scene 2. If no scene is specified, the playhead goes to the specified frame in the
current scene. You can use the scene parameter only on the root timeline, not within timelines
for movie clips or other objects in the document.
nextScene_mc.onRelease = function() {
gotoAndStop("Scene 2", 1);
}
Playing and stopping movie clips
Unless it is 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) {
// Plays the timeline that contains the button
play();
}