Writing Scripts with ActionScript > Assigning actions to a movie clip

 

Assigning actions to a movie clip

By assigning an action to a movie clip, you can make a movie perform an action when the movie clip is loaded or receives data. You must assign actions to an instance of the movie clip; other instances of the symbol aren't affected.

When you assign an action to a movie clip, you must nest the action inside an onClipEvent handler and specify the clip event that triggers the action. When you assign an action to a movie clip in normal mode, the onClipEvent handler is automatically inserted. You can choose an event from a list. (For more information about event handlers, see Controlling when ActionScript runs.)

You can also use events of the ActionScript MovieClip object and Button object to execute scripts. For more information on MovieClip and Button events, see Handling events with ActionScript.

The following instructions describe how to assign actions to movie clips using the Actions panel in normal mode. Once you've assigned an action, you test the movie to see whether it works.

 
To assign an action to a movie clip:

1

Select a movie clip instance and choose Window > Actions.

2

To assign an action, do one of the following:

Click a folder in the Actions toolbox (at the left side of the panel). Double-click an action to add it to the Script pane (at the right side of the panel).

Drag an action from theActions toolbox to the Script pane.

Click the Add (+) button and choose an action from the pop-up menu.

Use the keyboard shortcut listed next to an action in the Add (+) button pop-up menu.

Selecting an action from the Actions toolbox in normal mode
 

3

In the parameter boxes at the top of the panel, select parameters for the action as needed.

Parameters vary depending on the action you choose. For detailed information on the required parameters for each action, see the online ActionScript Dictionary in the Help menu. To insert a target path for a movie clip into a parameter text box, click the Insert Target Path button above the Script pane. For more information, see Working with Movie Clips and Buttons.

4

Repeat steps 2 and 3 to assign additional actions as necessary.

 
To test a movie clip action:

Choose Control > Test Movie.

For more information on using simple actions, see Controlling movie playback. For more information on creating interactivity, see Creating complex interactivity.