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

Assigning actions to a button

To make a movie perform an action when a button is clicked or rolled over, you can assign an action to the button. You must assign actions to an instance of the button; other instances of the symbol aren't affected.

When you assign an action to a button, you must nest the action inside an `on` handler and specify the mouse or keyboard events that trigger the action. When you assign an action to a button in normal mode, the `on` handler is automatically inserted and 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 Button object to execute scripts when a button event occurs. For more information, see Handling events with ActionScript.

The following instructions describe how to assign actions to a button 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 button:

1 | Select a button and choose Window > Actions to open the Actions panel if it isn't already open. Alternatively, you can select the button or movie clip instance from the jump menu in the Actions panel.
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 text boxes at the top of the panel, enter 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 button 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.