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.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 {
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:
Remarks:
This Flash tutorial how to use Keyboard to move objects of Flash Movies with Flash ActionScript.