Home | Contact Us | Store

Mouse Location Tracking with Flash ActionScript 3

Many Flash Movies require to track the location of mouse pointer as well as the status of the mouse pointer. This Flash ActionScript tutorial series show how to do some mouse control.
Your flash player version is too old to see this video file!

Flash Tutorial Content:

In this Flash ActionScript tutorial, we will write a very simple function so that the current location of Mouse Pointer can be tracked easily with ActionScript.

The complete Flash Movie is shown as above, you may try how it works before you start this tutorial.

Flash ActionScript Codes:

////////////////////////////////////////////////////////
///// Check the location of Mouse Pointer when click /////
////////////////////////////////////////////////////////
function mouseClickLoc(evt:MouseEvent):void {

output_txt.text = "The mouse click at: " + mouseX + "," + mouseY;

}


stage.addEventListener(MouseEvent.CLICK, mouseClickLoc);

/////////////////////////////////////////////////////////////////////////////
///// Keep tracking the location of moving Mouse Pointer /////
/////////////////////////////////////////////////////////////////////////////
function mouseMoveLoc(motion:MouseEvent):void {

output_txt.text = "Current mouse location: " + mouseX + "," + mouseY;

}


stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveLoc);

Download Flash Source File:

Flash Source File mouse-1.fla

Remarks:

Sometimes it also requires to know when the Mouse Pointer is over an object and when it leaves the object. The next Flash ActionScript tutorial will show how to do it.

Mouse Control Flash ActionScript Tutorial