Writing Scripts with ActionScript > Assigning actions to a frame |  |

Assigning actions to a frame

To make a movie perform an action when the playhead reaches a frame in the Timeline, you assign a frame action. For example, to create a loop in the Timeline between frames 20 and 10, you would add an action to frame 20 that sends the playhead to frame 10, as shown here:

    gotoAndPlay (10);

Some actions are commonly assigned to the first frame of a movie—for example, actions that define functions and set variables that create the initial state of your movie. In general, you can assign to the first frame any action you want to execute right as the movie starts. For more information about the order in which actions are executed, see Controlling when ActionScript runs.

It's a good idea to place all frame actions in a layer named Actions; that way, you can always find the actions in the Timeline. Once you've assigned an action, test the movie to see whether it works. The following instructions describe how to assign frame actions using the Actions panel in normal mode.

To assign an action to a frame:

1 | Select a keyframe in the Timeline, then choose Window > Actions or press F9.
| If a selected frame is not a keyframe, the action will be assigned to the previous keyframe.
2 | To assign an action, do one of the following:
| Click a folder in the Actions toolbox (at the left of the Actions panel) to open it. Double-click an action to add it to the Script pane (the right side of the panel).
| Drag an action from the Actions 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.
3 | Enter parameters for the action in the text boxes as needed.
4 | To assign additional actions, repeat steps 2 and 3.

Frames with actions display a small a in the Timeline.

To test a frame 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.