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

Get KeyCodes of Keyboard with Flash ActionScript 3

In this Flash ActionScript 3 tutorial, we show how to find out the keyCode of corresponding Keyboard keys with Flash ActionScript 3. Therefore you don't need to remember the keyCodes of Keyboard.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

Instead of using the arrow keys to move the ball in previous Flash ActionScript tutorial, you can also use other keys to move objects on the stage. You don't need to remember the keyCodes of keys on the Keyboard. You can check the keyCodes by using Flash ActionScript 3.

Please use the Mouse to click on the above Flash Movie and start playing to see how it works.

Flash ActionScript Codes:

// We need Keybpard control
import flash.events.KeyboardEvent;

// Declare variables
// Do not specify number so that TextFields can display the result
var keyCodeNumber;
var keyCtrlStatus;
var keyShiftStatus;

function whichKeyPress(evt:KeyboardEvent):void {

// Obtain key information
keyCodeNumber = evt.keyCode;
keyCtrlStatus = evt.ctrlKey;
keyShiftStatus = evt.shiftKey;

// Display results in TextFields
output_txt.text = keyCodeNumber;
ctrl_txt.text = keyCtrlStatus;
shift_txt.text = keyShiftStatus;

}

 

// Hook up the Keyboard event with whichKeyPress function
stage.addEventListener(KeyboardEvent.KEY_DOWN, whichKeyPress);

Download Flash Source File:

Flash Source File keyboard-3.fla

Remarks:

This Flash tutorial how to use Keyboard to move objects of Flash Movies with Flash ActionScript.