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.

See also<br />

onDragOut (Button.onDragOut h<strong>and</strong>ler)<br />

onKeyDown (Button.onKeyDown h<strong>and</strong>ler)<br />

onKeyDown = function() {}<br />

Invoked when a button has keyboard focus <strong>and</strong> a key is pressed. The onKeyDown event<br />

h<strong>and</strong>ler is invoked with no parameters. You can use the Key.getAscii() <strong>and</strong><br />

Key.getCode() methods to determine which key was pressed. You must define a function<br />

that is executed when the event h<strong>and</strong>ler is invoked.<br />

Example<br />

In the following example, a function that sends text to the Output panel is defined for the<br />

onKeyDown h<strong>and</strong>ler. Create a button called my_btn on the Stage, <strong>and</strong> enter the following<br />

ActionScript in a frame on the Timeline:<br />

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

trace("onKeyDown: "+this._name+" (Key: "+getKeyPressed()+")");<br />

};<br />

function getKeyPressed():String {<br />

var theKey:String;<br />

switch (Key.getAscii()) {<br />

case Key.BACKSPACE :<br />

theKey = "BACKSPACE";<br />

break;<br />

case Key.SPACE :<br />

theKey = "SPACE";<br />

break;<br />

default :<br />

theKey = chr(Key.getAscii());<br />

}<br />

return theKey;<br />

}<br />

Select Control > Test Movie to test the SWF file. Make sure you select Control > Disable<br />

Keyboard Shortcuts in the test environment. Then press the Tab key until the button has<br />

focus (a yellow rectangle appears around the my_btn instance) <strong>and</strong> start pressing keys on your<br />

keyboard. When you press keys, they are displayed in the Output panel.<br />

See also<br />

onKeyUp (Button.onKeyUp h<strong>and</strong>ler), getAscii (Key.getAscii method), getCode<br />

(Key.getCode method)<br />

262 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!