Tracking the cursor
position in Flash 4 can be accomplished with DragMovieClip function.
The cursor position can be obtained by dragging an invisible object
and getting the position of the object. It's simple but
it's rather tricky to implement.
(You might ask, "Why on earth ... there's no built in function to get the cursor
position in Flash 4?" Oops, I guess not. If you think
this makes things unnecessarily complicated, I agree.)
Step by step guide:
Create a new FLA (for this illustration purpose, use 300x200 size).
Insert/Create a new Symbol, and call the new Symbol: CursorTracker.
Set behavior to MovieClip. (This will be a blank symbol so no need to worry that the
symbol has nothing on it.)
On the first frame of the CursorTracker, insert the following
DragMovieClip("", lockcenter). This will cause the
CursorTracker to be dragged when the movie starts.
The second and third frame of CursorTracker will be a loop.
The loop will continuously get the mouse position. To accomplish that, do the
On the second frame insert the following action
Set Variable: "cusorX" = GetProperty ("",_x)
Set Variable: "cusorY" = GetProperty ("",_y) On the third frame, insert the following action:
Go to and Play(2)
That's it, you can then drag an instance of CursorTracker into
your movie and whenever you need to get the cursor position, the (x,y)
value is available at "CursorTracker:cursorX" and "CursorTracker:cursorY"
Below is an example to show how it works. You can also download the FLA file.
The CursorTracker symbol can be re-used independently in other movie by
dropping it into the main timeline.
There are some limitations that you should be aware of when using this
method. First, the object that tracks the cursor position must
always be dragged. That means that you cannot drag other object
while tracking the cursor position. It is possible to crate a workaround
by using any
dragged object to track the mouse position. For example, when you
drag Object1, you should get the cursor position from Object1, and when
you switch to Object2, you should get the cursor position from Object2,
etc. But frankly, that will be a pretty horrible task; and it is
impractical. Hope Flash 5 will include a built in function to obtain the cursor