The following procedure shows several ways to get the pointer position within the main Timeline
or within a movie clip.
To get the current pointer position:
Create two dynamic text fields, and name them box1_txt and box2_txt.
1.
Add labels for the text boxes: X position and Y position, respectively.
2.
Select Window > Development Panels > Actions to open the Actions panel if it is not already
3.
open.
Add only one of the following blocks of code to the script pane:
4.
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function() {
//returns the X and Y position of the mouse
box1_txt.text = _xmouse;
box2_txt.text = _ymouse;
};
Mouse.addListener(mouseListener);
Select Control > Test Movie to test the movie. The box1_txt and box2_txt fields show the
5.
position of the pointer while you move it over the Stage.
For more information about the methods of the Color class, see the Color class entry in
ActionScript Dictionary Help.. For more information about the
properties, see
MovieClip._xmouse
Capturing keypresses
For more information about the methods of the Color class, see the Color class entry in
ActionScript Dictionary Help.See the
ActionScript Language Reference Help.
You can use the methods of the built-in Key class to detect the last key pressed by the user. The
Key class does not require a constructor function; to use its methods, you simply call the methods
on the class, as shown in the following example:
Key.getCode();
You can obtain either virtual key codes or American Standard Code for Information Interchange
(ASCII) values of keypresses:
•
To obtain the virtual key code of the last key pressed, use the
•
To obtain the ASCII value of the last key pressed, use the
A virtual key code is assigned to every physical key on a keyboard. For example, the left arrow key
has the virtual key code 37. By using a virtual key code, you ensure that your SWF file's controls
are the same on every keyboard, regardless of language or platform.
ASCII values are assigned to the first 127 characters in every character set. ASCII values provide
information about a character on the screen. For example, the letter "A" and the letter "a" have
different ASCII values.
184
Chapter 6: Creating Interaction with ActionScript
and
MovieClip._ymouse
parameter of the
keyPress
and
_xmouse
_ymouse
in ActionScript Dictionary Help.
handler entry in
on()
method.
getCode()
method.
getAscii()
Need help?
Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?
Questions and answers