User Guide
Handling key and button events (Flash Professional only) 29
6. Open the Actions panel (Window > Actions), and enter the following code:
var myListener:Object = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
circle._x -= 10;
} else if (Key.getCode() == Key.RIGHT) {
circle._x += 10;
} else if (Key.getCode() == Key.UP) {
circle._y -= 10;
} else if (Key.getCode() == Key.DOWN) {
circle._y += 10;
}
};
Key.addListener(myListener);
7.
Test the application by selecting Control > Test Movie.
Press the four navigation keys on the emulator’s keypad (or the corresponding arrow keys
on your keyboard) to make the circle move around the Stage.
Using the soft keys (Flash Professional only)
To use the soft keys in your Flash Lite application, you must first call the SetSoftKeys
command. Subsequently, Flash Lite generates an
ExtendedKey.SOFT1 event when the user
presses the left soft key and an
ExtendedKey.SOFT2 event when the user presses the right soft
key. You write ActionScript event handler code that responds to these events and takes the
desired action.
The
SetSoftKeys command takes two parameters that specify the labels for the Left and
right soft keys, respectively, that appear when your application is not running in full-screen
mode. For applications running in full-screen mode, the labels that you specify are not visible,
so you must create your own labels and position them on the Stage where the soft keys are
located.
For example, consider the following
SetSoftKeys command call:
fscommand2("SetSoftKeys", "Options", "Exit");