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.

Example<br />

The following example defines a function for the onEnterFrame event h<strong>and</strong>ler that sends a<br />

trace() action to the Output panel:<br />

my_mc.onEnterFrame = function () {<br />

trace ("onEnterFrame called");<br />

}<br />

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

onKeyDown = function() {}<br />

Invoked when a movie clip has input focus <strong>and</strong> a key is pressed. The onKeyDown event h<strong>and</strong>ler<br />

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

methods to determine which key was pressed. You must define a function that executes when<br />

the event h<strong>and</strong>ler is invoked. You can define the function on the Timeline or in a class file that<br />

extends the MovieClip class or is linked to a symbol in the library.<br />

The onKeyDown event h<strong>and</strong>ler works only if the movie clip has input focus enabled <strong>and</strong> set.<br />

First, the MovieClip.focusEnabled property must be set to true for the movie clip. Then,<br />

the clip must be given focus. This can be done either by using Selection.setFocus() or by<br />

setting the Tab key to navigate to the clip.<br />

If Selection.setFocus() is used, the path for the movie clip must be passed to<br />

Selection.setFocus(). It is very easy for other elements to take the focus back after the<br />

mouse is moved.<br />

Example<br />

The following example defines a function for the onKeyDown() method that sends a trace()<br />

action to the Output panel. Create a movie clip called my_mc <strong>and</strong> add the following<br />

ActionScript to your FLA or AS file:<br />

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

trace ("key was pressed");<br />

}<br />

The movie clip must have focus for the onKeyDown event h<strong>and</strong>ler to work. Add the<br />

following ActionScript to set input focus:<br />

my_mc.tabEnabled = true;<br />

my_mc.focusEnabled = true;<br />

Selection.setFocus(my_mc);<br />

When you tab to the movie clip <strong>and</strong> press a key, key was pressed is displayed in the Output<br />

panel. However, this does not occur after you move the mouse, because the movie clip loses<br />

focus. Therefore, you should use Key.onKeyDown in most cases.<br />

MovieClip 453

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

Saved successfully!

Ooh no, something went wrong!