Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Creating Interaction with ActionScript > Creating interactivity and visual effects > Getting the pointer position | |||
You can use the _xmouse and _ymouse properties to find the location of the pointer in a SWF file. These properties could be used, for example, in a map application that gets the values of the _xmouse and _ymouse properties and uses the values to calculate the longitude and latitude of a specific location.
Each timeline has an _xmouse and _ymouse property that returns the location of the pointer within its coordinate system. The position is always relative to the registration point. For the main timeline (_level0), the registration point is the upper left corner. For a movie clip, the registration point depends on the registration point set when the clip was created or its placement on the Stage.
To see the _xmouse and _ymouse properties within the main timeline and a movie clip timeline, run the following SWF file and move your pointer. The updated coordinates on the right reflect the pointer position relative to the registration point of the smaller movie clip. The coordinates on the left reflect the pointer position on the larger SWF file.
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:
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);
For more information about the _xmouse and _ymouse properties, see _xmouse (MovieClip._xmouse property) and _ymouse (MovieClip._ymouse property) in the ActionScript 2.0 Language Reference.
|
|
|
|