Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

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.

Please read Learning ActionScript Function and Understand ActionScript Event before starting this Keyboard Events tutorial series.

Keyboard Events

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.

Keyboard key_down event

The following diagram illustrate that when a key of keyboard is released after pressed down, it will trigger the KEY_UP keyboard event.

keyboard key_up event

How to Register EventListener for Keyboard Event

Here's the procedures to register an EventListener for keyboard event.

  1. Decide the Keyboard event types (e.g. KEY_UP or KEY_DOWN) you wish to listen.
  2. Write a function for the Listener function with single KeyboardEvent parameter. This function will be called when the desire Keyboard events happen.
  3. 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.

Register event listener for keyboard event

In this example, when a visitor press on a key on the keyboard, the function (listenKeyEvent) will be called.

flash actionscript tutorial, flash animation tutorial