03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

keyListener.onKeyDown = function() {<br />

trace("For the last key typed:");<br />

trace("\tThe Key code is: "+Key.getCode());<br />

trace("\tThe ASCII value is: "+Key.getAscii());<br />

trace("");<br />

};<br />

Key.addListener(keyListener);<br />

When using this example, make sure that you select Control > Disable Keyboard Shortcuts in<br />

the test environment.<br />

getCode (Key.getCode method)<br />

public static getCode() : Number<br />

Returns the key code value of the last key pressed.<br />

Note: The Flash Lite implementation of this method returns a string or a number, depending<br />

on the key code passed in by the platform. The only valid key codes are the st<strong>and</strong>ard key codes<br />

accepted by this class <strong>and</strong> the special key codes listed as properties of the ExtendedKey class.<br />

Returns<br />

Number - The key code of the last key pressed. This method returns 0 if no key was pressed or<br />

released, or if the key code is not accessible for security reasons.<br />

Example<br />

The following example calls the getCode() method any time a key is pressed. The example<br />

creates a listener object named keyListener <strong>and</strong> defines a function that responds to the<br />

onKeyDown event by calling Key.getCode(). The keyListener object is then registered to<br />

the Key object, which broadcasts the onKeyDown message whenever a key is pressed while the<br />

SWF file plays.<br />

var keyListener:Object = new Object();<br />

keyListener.onKeyDown = function() {<br />

// Compare return value of getCode() to constant<br />

if (Key.getCode() == Key.ENTER) {<br />

trace ("Virtual key code: "+Key.getCode()+" (ENTER key)");<br />

}<br />

else {<br />

trace("Virtual key code: "+Key.getCode());<br />

}<br />

};<br />

Key.addListener(keyListener);<br />

When using this example, make sure that you select Control > Disable Keyboard Shortcuts in<br />

the test environment.<br />

352 ActionScript classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!