Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

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.

Please update flash player to view this Flash ActionScript tutorial!

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.