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();
}

This same on() event handler code will produce a different result when attached to a movie clip object rather than a button. When attached to a button object, statements made within an on() handler are applied to the Timeline that contains the button, by default. However, when attached to a movie clip object, statements made within an on() handler are applied to the movie clip to which the on() handler is attached.

For example, the following on() handler code stops the Timeline of the movie clip to which the handler is attached, not the Timeline that contains the movie clip.

on(press) {
  stop();
}

The same conditions apply to onClipEvent() handlers attached to movie clip objects. For instance, the following code stops the Timeline of the movie clip that bears the onClipEvent() handler when the clip first loads or appears on the Stage.

onClipEvent(load) {
  stop();
}