How to Get Mouse X & Y in ActionScript3
ActionScript allows programmers to code animated actions for users over the Web. These applications can monitor the actions of the user, while also playing movies, games or other animated content. Because of this, the capability to monitor such things as mouse position are built into the language. Using event listeners with the "mouseX" and "mouseY" values allows you to grab and monitor mouse position data.
Instructions
-
-
1
Create a basic ActionScript class:
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;public class Example{
}
-
2
Create an event listener that will capture mouse movements in the application:
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePosition);
-
-
3
Create a function "mousePosition" to store the "x" and "y" values of the mouse position when the mouse moves:
function mousePosition(event:MouseEvent){
mouse_x = String(mouseX);
mouse_y = String(mouseY);
}
-
1