03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - 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.

Registers an object to receive onKeyDown <strong>and</strong> onKeyUp notification. When a key is pressed or<br />

released, regardless of the input focus, all listening objects registered with addListener()<br />

have either their onKeyDown method or onKeyUp method invoked. Multiple objects can listen<br />

for keyboard notifications. If the listener newListener is already registered, no change occurs.<br />

A Flash application can only monitor keyboard events that occur within its focus. A Flash<br />

application cannot detect keyboard events in another application.<br />

Availability: <strong>ActionScript</strong> 1.0; Flash Player 6<br />

Parameters<br />

listener:Object - An object with methods onKeyDown <strong>and</strong> onKeyUp.<br />

Example<br />

The following example creates a new listener object <strong>and</strong> defines a function for onKeyDown <strong>and</strong><br />

onKeyUp. The last line uses addListener() to register the listener with the Key object so that<br />

it can receive notification from the key down <strong>and</strong> key up events.<br />

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

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

trace ("You pressed a key.");<br />

}<br />

myListener.onKeyUp = function () {<br />

trace ("You released a key.");<br />

}<br />

Key.addListener(myListener);<br />

The following example assigns the keyboard shortcut Control+7 to a button with an instance<br />

name of my_btn <strong>and</strong> makes information about the shortcut available to screen readers (see<br />

_accProps). In this example, when you press Control+7 the myOnPress function displays the<br />

text hello in the Output panel.<br />

function myOnPress() {<br />

trace("hello");<br />

}<br />

function myOnKeyDown() {<br />

// 55 is key code for 7<br />

if (Key.isDown(Key.CONTROL) && Key.getCode() == 55) {<br />

Selection.setFocus(my_btn);<br />

my_btn.onPress();<br />

}<br />

}<br />

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

myListener.onKeyDown = myOnKeyDown;<br />

Key.addListener(myListener);<br />

my_btn.onPress = myOnPress;<br />

my_btn._accProps.shortcut = "Ctrl+7";<br />

Accessibility.updateProperties();<br />

682 <strong>ActionScript</strong> classes

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

Saved successfully!

Ooh no, something went wrong!