![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
You can use the _xmouse
and _ymouse
properties to find the location of the mouse pointer (cursor) in a SWF file. Each Timeline has an _xmouse
and _ymouse
property that returns the location of the mouse 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.
To see the _xmouse
and _ymouse
properties within the main Timeline and a movie clip Timeline, run the SWF file below and move your mouse pointer. The updated coordinates on the right reflect the mouse position relative to the registration point of the smaller movie clip. The coordinates on the left reflect the mouse position on the larger SWF file.
The following procedures show two ways to get the mouse position.
x_pos
and y_pos
._level0
SWF file:
x_pos = _root._xmouse; y_pos = _root._ymouse;
The variables x_pos
and y_pos
are used as containers to hold the values of the mouse positions. You could use these variables in any script in your document. In the following onClipEvent()
handler, the values of x_pos
and y_pos
update every time the user moves the mouse.
onClipEvent(mouseMove){ x_pos = _root._xmouse; y_pos = _root._ymouse; }
myMovieClip
.For example, the following statement could be placed on any Timeline in the _level0
SWF file to return the _ymouse
position in the myMovieClip
instance:
x_pos = _root.myMovieClip._xmouse y_pos = _root.myMovieClip._ymouse
The code returns the _xpos
and _ypos
of the mouse, relative to the registration point.
You can also determine the mouse position within a movie clip by using the _xmouse
and _ymouse
properties in a clip event, as shown in the following code:
onClipEvent(enterFrame){ xmousePosition = this._xmouse; ymousePosition = this._ymouse; }
For more information about the _xmouse
and _ymouse
properties, see MovieClip._xmouse
and MovieClip._ymouse
.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |