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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

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

if (Key.isDown(Key.ESCAPE)) {<br />

// get the current timer, convert the value to seconds <strong>and</strong> round it to two<br />

decimal places.<br />

var timer:Number = Math.round(getTimer()/10)/100;<br />

trace("you pressed the Esc key: "+getTimer()+" ms ("+timer+" s)");<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 />

getAscii (Key.getAscii method)<br />

public static getAscii() : Number<br />

Returns the ASCII code of the last key pressed or released. The ASCII values returned are<br />

English keyboard values. For example, if you press Shift+2, Key.getAscii() returns @ on a<br />

Japanese keyboard, which is the same as it does on an English keyboard.<br />

Returns<br />

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

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

Example<br />

The following example calls the getAscii() 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.getAscii(). 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 />

trace("The ASCII code for the last key typed is: "+Key.getAscii());<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 />

The following example adds a call to Key.getAscii() to show how getAscii() <strong>and</strong><br />

getCode() differ. The main difference is that Key.getAscii() differentiates between<br />

uppercase <strong>and</strong> lowercase letters, <strong>and</strong> Key.getCode() does not.<br />

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

Key 351

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

Saved successfully!

Ooh no, something went wrong!