MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference page 379

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

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() {
// Compare return value of getCode() to constant
if (Key.getCode() == Key.ENTER) {
trace ("Virtual key code: "+Key.getCode()+" (ENTER key)");
}
else {
trace("Virtual key code: "+Key.getCode());
}
};
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
The main difference is that
letters, 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.
See also
getAscii (Key.getAscii method)
method any time a key is pressed. The example
getCode()
and defines a function that responds to the
keyListener
. The
Key.getCode()
onKeyDown
Key.getAscii()
differentiates between uppercase and lowercase
Key.getAscii()
does not.
object is then registered to
keyListener
message whenever a key is pressed while the
to show how the two methods differ.
Key
379

Advertisement

Table of Contents
loading

Table of Contents