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.

Example<br />

The following example attaches a draggable movie clip called car_mc at the x <strong>and</strong> y<br />

coordinates of 0,0. When you press the Home key, car_mc returns to 0,0. Create a movie clip<br />

that has a linkage ID car_id, <strong>and</strong> add the following <strong>ActionScript</strong> to Frame 1 of the Timeline:<br />

this.attachMovie("car_id", "car_mc", this.getNextHighestDepth(), {_x:0,<br />

_y:0});<br />

car_mc.onPress = function() {<br />

this.startDrag();<br />

};<br />

car_mc.onRelease = function() {<br />

this.stopDrag();<br />

};<br />

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

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

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

car_mc._x = 0;<br />

car_mc._y = 0;<br />

}<br />

};<br />

Key.addListener(keyListener);<br />

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player<br />

7 or later. If your SWF file includes a version 2 component, use the version 2 components'<br />

DepthManager class instead of the MovieClip.getNextHighestDepth() method.<br />

INSERT (Key.INSERT property)<br />

public static INSERT : Number<br />

The key code value for the Insert key (45).<br />

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

Example<br />

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

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

receive notification from the key down event <strong>and</strong> display information in the Output panel.<br />

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

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

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

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

}<br />

};<br />

Key.addListener(keyListener);<br />

Key 691

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

Saved successfully!

Ooh no, something went wrong!