• 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 Press mouse event allows viewers to trigger actions from the keyboard by pressing a specified key. Although you assign it to a button, on (press) 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:

Create a new Flash document with keyframes in the first two frames.

Use the text tool to add text that idengifies each frame (Scene 1•Frame 1 and Scene 1•Frame 2).

Add a stop action to each frame so that the movie doesn't loop through the frames on playback.

Place a single button instance in Frame 1, and select the button.

Access the Object Actions panel.

From the Add Statement menu, choose Basic Actions > On Mouse Event.

In the Event section of the Parameters pane, uncheck the Release checkbox.

Check the Key Press checkbox, and type the letter A in the text field (Figure 13.27).

Figure 13.27. When you select Key Press from the Event parameters for an On Mouse Event action, you must specify the triggering key by typing it in the text field.

Flash adds on (keyPress "A"). In the final movie, pressing the letter A on the keyboard triggers whatever actions you specify in this action sequence.

With on (keyPress "A") selected in the Actions List, from the Add Statement menu, choose Basic Actions > Go To.

From the Parameters pane's Type menu choose Frame Number, and enter 2 in the Frame field.

Flash adds gotoAndPlay (2); to the Actions List between the curly braces (Figure 13.28).

Figure 13.28. This action sequence makes Flash jump to Frame 2 when the user presses A on the keyboard at a time when this button is present 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