• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 13. Interactivity with Objects > Triggering Button Actions from the Key...

Triggering Button Actions from the Keyboard

The On keyPress mouse event allows viewers to trigger actions from the keyboard by pressing a specified key. Although you assign it to a button, on (keyPress) affects the entire range of frames in which it resides. The button’s Hit-frame graphic need not cover the whole Stage, and the user need not position the pointer over the button before pressing the specified key. Whenever the button is in the currently displayed frame, pressing the specified key triggers the assigned actions.

To set up an action triggered by a key press:

Open a new copy of the ObjectActions Template that you created in “To set up a document for testing actions,” earlier in this chapter (a movie with five keyframes and a stop action in Keyframe 1).

In Keyframe 1, select the button on the Stage.

Access the Actions-Button panel.

From the Add menu, choose Actions > Movie Control > on.

In the Event section of the parameters area, do the following:

  • Uncheck the Release checkbox

  • Check the Key Press checkbox.

  • Type A in the text field (Figure 13.29).

    Figure 13.29. When you select Key Press as the Event parameter for an on action, you must specify the triggering key by typing it in the text field.

    Flash places on (keyPress “A”) and a set of curly braces in the Script pane. In the final movie, pressing the letter A on the keyboard triggers whatever actions you specify in this script.

With on (keyPress “A”) { (Line 1) selected in the Script pane, from the Ad menu, choose Actions > Movie Control > goto.

In the parameters area, do the following:

  • Choose Go to and Stop.

  • From the Type pop-up menu, choose Frame Number.

  • Enter 2 in the Frame field.

    Flash adds gotoAndStop (2); to Line 2 in the Script pane between the curly braces (Figure 13.30).

    Figure 13.30. This script makes Flash jump to Frame 2 when the user presses A on the keyboard at a time when this button is being displayed in the movie.

    You’re ready to see the button in action.

Choose Control > Test Movie.

Flash exports the movie and opens it in Flash Player. No matter where the pointer is, when the button is on-screen and you press A on the keyboard, Flash jumps to Frame 2 of the movie.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint