How to check if the mouse is over an instance of a character using ActionScript 3 in Flash

How to check if the mouse is over an instance of a character using ActionScript 3 / Flash CS5?

+4
source share
3 answers

See getObjectsUnderPoint if you want a list of all objects that are children of the display object container.

Otherwise, you can use hitTestPoint and pass the point with the coordinates mouseX and mouseY.

+6
source

Juan Pablo is right, but I found that hitTestPoint can be elusive if not applied correctly. In particular, the third argument (shapeFlag Boolean) should be TRUE (defaults to FALSE), and using event.stageX / Y in mouse events often works when mouseX / Y does not.

I can’t explain why, but the following pretty convincing evidence in my experience:

if (hitTestPoint(event.stageX, event.stageY, true)) // Do something 
+1
source

Why not use MouseEvent?

 symbol.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); function onMouseOver(evt:MouseEvent):void { //is called when mouse is over your symbol. } 
0
source

All Articles