Macromedia Flash 8 for Windows & Macintosh

Most Flash creations employ a mixture of interface objects: button symbols, button components, and movie clips. More advanced ActionScripters can add script to control other types of objects. Flash's assisted scripting modes aren't quite as open ended, but you can use them to create scripts that control the playback of movie clips. You can script a button to start and stop a movie clip, or script a button component to jump to a specific frame in a movie clip. The key is to specify the correct target path. As you saw in "Adding Actions to Buttons," earlier in this chapter, Script Assist can handle target paths for buttons but not for movie-clip symbols or components. For the following task, use the Behaviors panel.

To make a button symbol stop movie-clip playback

1.

Open a new Flash document, and access the Actions and Behaviors panels.

2.

Place one instance of a button symbol, a button component, and an animated movie-clip symbol (for example, one containing a simple motion tween of a spinning star) on the Stage.

3.

Select the button-symbol instance.

4.

From the Add menu in the Behaviors panel, select Movieclip > Goto and Stop at frame or label.

The Goto and Stop dialog appears.

5.

In the target movie-clip pane, select the movie clip instance.

For one object to control another, the object that is being controlled must have an instance name. Because you didn't name the movie-clip instance name in step 2, a warning dialog appears (Figure 13.66).

Figure 13.66. When you want to set up a button that controls playback of a movie clip, the target movie clip must have an instance name. Flash warns you if you select an instance that lacks an instance name. Click the Rename button to give the instance a name.

Tips for Naming Instances

A movie clip's instance name may wind up being part of the pathname in a script. Therefore, you must be careful how you name the instances of buttons and movie clips. Use letters and numbers; feel free to use the underscore character or capitalization to act as word dividers. Don't use spaces or other punctuation marks, because these may have special meanings in ActionScript and create errors in scripting.

6.

In the Rename dialog, click the Rename button.

The Instance Name dialog appears.

7.

Enter an instance name for your movie clipfor example, ControlledClip_mc (Figure 13.67).

Figure 13.67. The Instance Name dialog allows you to name an instance while you're setting parameters in the Goto dialog. Otherwise, you would have to return to the Stage, select the instance, and enter a name for it in the Properties tab of the Property inspector.

8.

Click OK.

Flash returns you to the Goto and Stop dialog. Leave the other parameters at their default settings: Relative pathname, with frame 1 as the target frame on which to stop playback.

9.

In the Goto and Stop dialog, click OK.

10.

On the Stage, select the button-component instance.

11.

From the Add menu in the Behaviors panel, select Movieclip > Goto and Play at frame or label.

Flash opens the Goto and Play dialog. (Because you already named the movie-clip instance, the Rename warning dialog doesn't appear.)

12.

In the Goto and Play dialog, set the following parameters.

  • Select ControlledClip_mc as the target movie clip.
  • Select Relative as the pathname style.

  • Type 1 in the target-frame field (Figure 13.68).

    Figure 13.68. The parameters for Goto and Play are just like those for Goto and Stop. When you opt to control a movie clip with a button, the target frame is the frame in the movie clip that you want to jump to. To start the movie clip at the beginning, choose frame 1.

13.

Click OK. You're ready to test your buttons in Flash Player. When you click the button symbol, the animated movie clip goes back to its first frame and stops playing. Click the button component, and the movie clip resumes playing.

Категории