Flash ActionScript 3 Keyboard Events Tutorials
The most common user interaction with Flash Movies should be the keyboard and mouse. In this Flash ActionScript tutorial, we will discuss how to use keyboard to interact with Flash Movie.
The Keyboard Events are:
When a key is pressed down
When a key is released
The following diagram illustrate that when a key of keyboard is pressed down, it will trigger the KEY_DOWN keyboard event.
The following diagram illustrate that when a key of keyboard is released after pressed down, it will trigger the KEY_UP keyboard event.
How to Register EventListener for Keyboard Event
Here's the procedures to register an EventListener for keyboard event.
- Decide the Keyboard event types (e.g. KEY_UP or KEY_DOWN) you wish to listen.
- Write a function for the Listener function with single KeyboardEvent parameter. This function will be called when the desire Keyboard events happen.
- Register or hook up the function with the stage that is given instruction to listen to the keyboard event.
The following diagram illustrate how to register an EventListener for a Keyboard Event.
In this example, when a visitor press on a key on the keyboard, the function (listenKeyEvent) will be called.