Retrieving position relative to application window is easy, but to get position relative to screen we need to use slightly different approach.
By using globalToScreen we can retrieve mouse position relative to screen.
First, we have to add event listener for mouse move to application. We will insert this in creationComplete event:
application.addEventListener(MouseEvent.MOUSE_MOVE, reflectMouse);
Also, we are going to add Lable element where we will display current mouse position:
<mx:Label x="10" y="10" text="Label" width="165" id="myMouse"/>
Now, create function that will track mouse position:
private function reflectMouse(event:MouseEvent):void
{
var myMousePos:Point = application.stage.nativeWindow.globalToScreen(new Point(application.mouseX, application.mouseY));
myMouse.text = "X:" + myMousePos.x + " / Y: " + myMousePos.y;
}
That's it!
Happy coding!
+