MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 601

Actionscript language reference
Table of Contents

Advertisement

MovieClip.onKeyDown
Availability
Flash Player 6.
Usage
my_mc.onKeyDown = function() {
// your statements here
}
Parameters
None.
Returns
Nothing.
Description
Event handler; invoked when a movie clip has input focus and a key is pressed. The
event handler is invoked with no parameters. You can use the
Key.getCode()
executes when the event handler is invoked. You can define the function on the Timeline or in a
class file that extends the MovieClip class or is linked to a symbol in the library.
The
onKeyDown
the
MovieClip.focusEnabled
must be given focus. This can be done either by using
Tab key to navigate to the clip.
If
Selection.setFocus()
Selection.setFocus()
is moved.
Example
The following example defines a function for the
method to the log file. Create a movie clip called my_mc and add the following
trace()
ActionScript to your FLA or AS file:
my_mc.onKeyDown = function() {
trace("key was pressed");
};
The movie clip must have focus for the
ActionScript to set input focus.
my_mc.tabEnabled = true;
my_mc.focusEnabled = true;
Selection.setFocus(my_mc);
When you tab to the movie clip and press a key,
However, this does not occur after you move the mouse, because the movie clip loses focus.
Therefore, you should use
methods to determine which key was pressed. You must define a function that
event handler works only if the movie clip has input focus enabled and set. First,
property must be set to
is used, the path for the movie clip must be passed to
. It is very easy for other elements to take the focus back after the mouse
Key.onKeyDown
for the movie clip. Then, the clip
true
Selection.setFocus()
onKeyDown()
event handler to work. Add the following
onKeyDown
key was pressed
in most cases.
and
Key.getAscii()
or by setting the
method that writes the results a
writes to the log file.
MovieClip.onKeyDown
onKeyDown
601

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents