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.

The key code value for the Left Arrow key (37).<br />

Example<br />

The following example moves a movie clip called car_mc a constant distance (10) when you<br />

press the arrow keys. A sound plays when you press the Spacebar. Give a sound in the library a<br />

linkage identifier of horn_id for this example.<br />

var DISTANCE:Number = 10;<br />

var horn_sound:Sound = new Sound();<br />

horn_sound.attachSound("horn_id");<br />

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

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

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

case Key.SPACE :<br />

horn_sound.start();<br />

break;<br />

case Key.LEFT :<br />

car_mc._x -= DISTANCE;<br />

break;<br />

case Key.UP :<br />

car_mc._y -= DISTANCE;<br />

break;<br />

case Key.RIGHT :<br />

car_mc._x += DISTANCE;<br />

break;<br />

case Key.DOWN :<br />

car_mc._y += DISTANCE;<br />

break;<br />

}<br />

};<br />

Key.addListener(keyListener_obj);<br />

_listeners (Key._listeners property)<br />

public static _listeners : Array [read-only]<br />

A list of references to all listener objects registered with the Key object. This property is<br />

intended for internal use, but may be useful if you want to ascertain the number of listeners<br />

currently registered with the Key object. Objects are added <strong>and</strong> removed from this array by<br />

calls to the addListener() <strong>and</strong> removelistener() methods.<br />

Example<br />

The following example shows how to use the length property to ascertain the number of<br />

listener objects currently registered to the Key object.<br />

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

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

Key 355

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

Saved successfully!

Ooh no, something went wrong!