Add a stop() Statement in Flash CS5 ActionScript - dummies

By Jennifer Smith, Christopher Smith, Fred Gerantabee

The stop() statement in Adobe Flash Creative Suite 5 ActionScript does exactly what it sounds like: It stops the Flash CS5 timeline at whatever frames it’s placed on. A common use of stop() is to keep a movie from looping, which is the default behavior for Flash Player.

Follow these steps to create a stop action in your movie:

  1. On a new layer, create a motion or shape tween from frames 1 through 24 and press Enter or Return to play back and preview the animation.

  2. Click the New Layer button below the timeline to create a new layer and name it Actions. If necessary, drag the layer upward so that it’s the topmost layer in the stack.

    This dedicated layer is where you add ActionScript to control your new motion tween.

  3. Add a keyframe on frame 24 of the new Actions layer with the F6 shortcut key.

  4. Select the keyframe and choose Window→Actions to launch the Actions panel.

  5. In the Actions panel, locate the Script Assist button and click it.

    The top panel expands, and you’re now working in Script Assist mode.

You can add ActionScript to keyframes with existing content, but it’s always a good practice to separate scripts from visual elements on the stage by creating a dedicated layer for your ActionScript.

  1. Click the plus sign at the top of the Actions panel and choose flash.display→MovieClip→Methods→Stop.

  2. Specify in the Object text box the name of the object you want to control. Because you’re stopping the current (main) timeline, enter the word this in place of the not_set_yet text in the Object text box.



    The actions panel reads

    import flash.display.MovieClip;

    Take a look at your, and you’ll notice that a lowercase a now appears inside the keyframe, which indicates that there is ActionScript on the keyframe. These scripts run when the playhead passes that keyframe.

  3. Choose Control→Test Movie to preview your movie.

    The animation plays until frame 24 and then stops.