Key.getAscii()
Availability
Flash Player 5.
Usage
Key.getAscii() : Number
Parameters
None.
Returns
A number; an integer that represents the ASCII value of the last key pressed.
Description
Method; returns the ASCII code of the last key pressed or released. The ASCII values returned are
English keyboard values. For example, if you press Shift+2,
Japanese keyboard, which is the same as it does on an English keyboard.
Example
The following example calls the
creates a listener object named
event by calling
onKeyDown
in Using ActionScript in Flash. The
broadcasts the
onKeyDown
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
main difference is that
and
Key.getCode()
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.
getAscii()
keyListener
Key.getAscii()
keyListener
message whenever a key is pressed while the SWF file plays.
Key.getAscii()
differentiates between uppercase and lowercase letters,
Key.getAscii()
does not.
Key.getAscii()
method any time a key is pressed. The example
and defines a function that responds to the
. For more information, see "Using event listeners"
object is then registered to the
to show how the two methods differ. The
returns
on a
@
object, which
Key
Key.getAscii()
353
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?
Questions and answers