Example
The following example calls the
creates a listener object named
event by calling
onKeyDown
the
object, which broadcasts the
Key
SWF file plays.
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("The ASCII code for the last key typed is: "+Key.getAscii());
};
Key.addListener(keyListener);
When using this example, make sure that you select Control > Disable Keyboard Shortcuts in
the test environment.
The following example adds a call to
differ. The main difference is that
getCode()
uppercase and lowercase letters, and
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("For the last key typed:");
trace("\tThe Key code is: "+Key.getCode());
trace("\tThe ASCII value is: "+Key.getAscii());
trace("");
};
Key.addListener(keyListener);
When using this example, make sure that you select Control > Disable Keyboard Shortcuts in
the test environment.
getCode (Key.getCode method)
public static getCode() : Number
Returns the key code value of the last key pressed.
Note: The Flash Lite implementation of this method returns a string or a number, depending
on the key code passed in by the platform. The only valid key codes are the standard key codes
accepted by this class and the special key codes listed as properties of the ExtendedKey class.
Availability: ActionScript 1.0; Flash Lite 2.0
Returns
- The key code of the last key pressed. This method returns 0 if no key was pressed or
Number
released, or if the key code is not accessible for security reasons.
378
ActionScript classes
method any time a key is pressed. The example
getAscii()
and defines a function that responds to the
keyListener
. The
Key.getAscii()
onKeyDown
Key.getAscii()
Key.getAscii()
Key.getCode()
object is then registered to
keyListener
message whenever a key is pressed while the
to show how
getAscii()
differentiates between
does not.
and
Need help?
Do you have a question about the FLASHLITE2 ACTIONSCRIPT-LANGUAGE and is the answer not in the manual?