FireworksColdFusionDreamweaverFreehandFlashMXHome
Past Week's New Content

Latest Free Content
View All
Free Content
Accessibility
CMX Learning Guides
Hosted by enterhost

Capturing X and Y coordinates in Flash MX

Knowledge Base

Posted by Matthew David

It is useful to know where your X and Y cooridinates for a cursor are on the stage.

Cut and paste the following ActionScript and paste it into Flash. You will only need one frame to run this program. What you are capturing are the X and Y coordinates for the mouse. This is useful for games and other interactive presentations you will build with Flash MX:

//Create the dynamic text fields that will display the positions
//of X and Y for the cursor
createTextField("shortDate", 2, 100, 125, 200, 200);
createTextField("yTxt", 3, 100, 145, 200, 200);

//Define the style Sheet for the text
myStyle = new TextFormat();
myStyle.color = 0x333333;
myStyle.font = "Trebuchet MS";

//Create a new object watch the mouse
watchMouse = new Object();

//Decalre a function to run when the Mouse moves on the stage
watchMouse.onMouseMove = function() {
shortDate.text = "X position of cursor is: "+_xmouse;
shortDate.setTextFormat(myStyle);
yTxt.text = "Y position of cursor is: "+_ymouse;
yTxt.setTextFormat(myStyle);
};

//Add listener to to mouse object
Mouse.addListener(watchMouse);