User Guide

Creating interactivity and visual effects 185
To decide which keys to use and determine their virtual key codes, use one of the following
approaches:
See the list of key codes in Appendix C, “Keyboard Keys and Key Code Values,” on page 313.
See the list of key codes in Appendix C, “Keyboard Keys and Key Code Values,” in
ActionScript Dictionary Help.
Use a Key class constant. (In the Actions toolbox, click Built-in Classes > Movie > Key >
Constants.)
Assign the following onClipEvent() handler to a movie clip, and select Control > Test Movie
and press the desired key:
onClipEvent(keyDown) {
trace(Key.getCode());
}
The key code of the desired key appears in the Output panel.
A common place to use Key class methods is within an event handler. In the following example,
the user moves the car using the arrow keys. The
Key.isDown() method indicates whether the
key being pressed is the right, left, up, or down arrow. The event handler,
onEnterFrame,
determines the
Key.isDown(keyCode) value from the if statements. Depending on the value,
the handler instructs Flash Player to update the position of the car and to show the direction.
The input from the keyboard keys moves the car.