.
.
 
Mouse Tracking

There are many uses for tracking the mouse, it is vital for games and the higher interactive Flash movies that you have seen around. This tutorial works with Flash 4, Flash 5 has the added functionality of "MouseX" and "MouseY" properties for this purpose.

Download MouseTracking.fla used in this example.

Dissymmetry Basic Flash Tutorial (5,214 bytes)

1) Begin by inserting a blank Movie Clip instance onto the stage. And name the instance "Mouse". Then edit the clip and place the following action script in the first frame:

Set Variable: "Coord" = "(" & GetProperty("",_x) & ", " & GetProperty("",_y) & ")"
Comment: Variable = String, Value = Expression

and the following script in the second frame:

Set Variable: "Coord" = "(" & GetProperty("",_x) & ", " & GetProperty("",_y) & ")"
Comment: Variable = String, Value = Expression
GoTo and Play(1)

For other applications, you will most likely want to use separate variables for the _x and _y properties, in which case you would use the following instead:

Set Variable: "CoordX" = GetProperty("",_x)
Comment: Variable = String, Value = Expression
Set Variable: "CoordY" = GetProperty("",_y)
Comment: Variable = String, Value = Expression

2) Return to the main scene and insert a new layer, name the layer "Events". Insert the following action script in the first frame:

Start Drag ("/Mouse", lockcenter)
Comment: Target = String, "Lock Mouse to Center" = True

3) To view the mouse tracking in action, insert a Text Box and edit the box's properties. Link it to "/Mouse:Coord" as the variable.

 

.
Right-Bottom 006699.gif (866 bytes)

"The Internet is the foundation for a new industrial order. ... If you don't believe deeply, wholly...that the Net is going to change your business, you're going to lose."  - Fortune Magazine

All graphics on this site are copyrighted by their respective distributors and may not be duplicated, modified in any fashion or used in any way without consent.

Last Updated: 12/5/07

Home |  Tutorials |  Basic |  Intermediate |  Advanced |  Contact Us