Flash Mouse Coordinates

Monkey Forums/Monkey Bug Reports/Flash Mouse Coordinates

mr_twister(Posted 2012) [#1]
Hi,
I found a weird behavior in Flash regarding mouse movement when additional child objects are placed on screen.

I made a small module that adds a child element to the "stage" and while adding the element works, once you hover the mouse over the element, the MouseX(), MouseY() reported by Monkey become local coordinates inside the object instead of the coordinates inside the screen.

Researching a bit into the issue I found that when parsing the MouseEvent in the MouseOver() callback, Monkey is using localX and localY:

stage.addEventListener( MouseEvent.MOUSE_MOVE,function( e:MouseEvent ):void{
	OnMouseMove( e.localX,e.localY );
} );


It seems that both should be replaced by stageX and stageY in order to get the correct coordinates every time.


marksibly(Posted 2012) [#2]
Hi,

I dunno...why is reporting mouse in scene coords any more (or less) correct than reporting mouse in local coords?

Wont it depend on what you're trying to achieve and just why you have multiple child objects?


mr_twister(Posted 2012) [#3]
localX and localY in the mouse event always report the coords relative to the object which the mouse is hovering over that is lowest in the scene hierarchy. The mouse event always contain both global and local coords as stated above.

I needed to add child objects to the stage to implement buttons properly so I could launch pages when the user clicked on them without chrome blocking the window (If navigateToUrl is invoked from outside a Flash event handler, Chrome blocks it, to prevent spammy apps which launch sites without consent from the user).

By doing that however I lost accurate track of the mouse position through MouseX() and MouseY() since once you hover over the "child button" the coords reported by Monkey become relative to that object, not the whole scene.

Using stageX and stageY works btw. Could this change be added to the official Monkey distribution? (as long as it doesn't break any code of yours, but Monkey seem to be working fairly fine since I added the fix in my local install).


marksibly(Posted 2012) [#4]
Hi,

> once you hover over the "child button" the coords reported by Monkey become relative to that object, not the whole scene

Ok, that sounds bad!

But I guess what we really want then is the 'game bitmap relative' mouse coords - ie: isn't there a chance the game bitmap could be offset into the stage, ie: it could be parented to something else and/or its x/y could be non-zero, in which case stage coords would be wrong?

Will definitely at least do the stageX, stageY fix, but if you can come up with something better...