Mouse.cursor in Flash CS4 (AS3) Thinking in the Fifth Dimension
Nov 052009

From time to time you might find it necessary to track the cursor when working with Flash.  Fortunately, this is fairly easy.

As with all things Flash when dealing with values, you should create the variables beforehand so as to prevent loads of errors when compiling.

Here’s the code, it uses an Event Listener:

var yCoord:Number = 0;
var xCoord:Number = 0;

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove); function mouseMove(event:MouseEvent){
yCoord = mouseY;
xCoord = mouseX;
} );

yCoord and xCoord would be your mouse coordinates.  This Event Listener is called on on the stage to ensure that you get the coordinates whenever the mouse moves across the stage.  In the event that you would like the mouse to be tracked only on a particular movie clip, exchange the “stage” identifier for the identifier of the movie clip you want to track the movements on.

Hope this helps someone…

/A\V/

Posted by Alexander Tagged with: , ,

Leave a Reply

(required)

(required)