Adobe Flash

Add a script to a button by using Script Assist mode

In this section you'll use Script Assist mode to add a script to the Home button. When the sample application is run and the Home button is clicked, the Home title appears in the Title movie clip.

  1. Click the Selection tool in the Tools panel.

  2. On the Timeline, select the "menu and button" layer.

    If the layer is locked, unlock it.
  3. In the upper-right corner of the Stage, select the Home button.

  4. In the Actions panel, you'll see the Script Assist button above the ActionScript editor.

    Click Script Assist to display Script Assist mode.

    With no functions selected, the Script Assist pane is blank.

    [View full size image]

    Initially, the Script Assist portion of the Actions panel is blank. Script Assist mode prompts you to select options and set parameters for the functions that you add to the selected button. The parameters are displayed when you add an ActionScript function.

    Note: You may notice that when Script Assist mode is enabled, you cannot directly edit code in the ActionScript editor, because it is read-only. All interaction with the code in the editor is through Script Assist mode with one important exception: you can highlight functions in the ActionScript editor and delete them.

  5. To add a function to the button, click Add on the toolbar.

    Clicking the Add button displays all of the predefined ActionScript functions.

  6. From the Movie Clip Control option, select the on event handler.

    Note: An alternative method of adding ActionScript functions is to browse for and then select them from the Actions toolbox. The Add button on the Actions panel toolbar and the Actions toolbox display the same categories of functions and you can add functions to the editor from both.

    Script Assist mode prompts you to set the function's parameters.

    [View full size image]

    The release event of the on event handler is selected by default.

    You'll use the release event to trigger the script action when the user clicks Home.

  7. Click Add again and then select the goto() function from the Global Functions > Timeline Control option.

    Adding the function that is triggered when the event occurs

    [View full size image]

    The goto() function is added as the action of the on event handler. In other words, when the Home button is pressed (the on handler) and released (the release event), the goto() action is executed.

    When the Home button is clicked, the movie clip should move to and stop at the Home frame of the Timeline. To do this, you use Script Assist mode to modify the default parameters of the goto() function.

  8. In the Script Assist panel, select the Go To and Stop option.

  9. Set the Type to Frame Label by selecting it from the Type pop-up menu.

  10. In the Frame text box, enter home.

Modifying function parameters to complete the script

The changes you made with Script Assist mode are displayed in the ActionScript editor. You've just created a script without manually writing code in the ActionScript editor.

When you test the application, clicking the Home button will display the title "Home" in the Title movie clip, indicating that the Home frame is currently displayed.

Clicking the Home button displays "Home" in the Title movie clip.

You could repeat this process for the About, Products, and Contacts buttons. However, for these buttons you'll use an alternative and preferred method for creating scripts.

In each case, you want to display the related frames on the Timeline when each of the buttons are clicked; therefore, you will set the frame target of the gotoAndStop() function to the About, Products, and Contacts frames, as you've just done for the Home button.