开发者

How to check if mouse is over a symbol instance with ActionScript 3 in Flash

How does one check if mouse is over a symbol instance using ActionScript 开发者_如何转开发3 / Flash CS5?


Check out the getObjectsUnderPoint method if you want to get a list of all the objects that are children of a display object container.

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


Juan Pablo is correct, but I've found that hitTestPoint can be finicky if not applied correctly. Specifically, the third argument (shapeFlag Boolean) should be TRUE (Default is FALSE) and using event.stageX/Y on mouse events often works when mouseX/Y does not.

Can't explain why exactly, but the following is pretty fool proof in my experience:

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


Why not use a MouseEvent?

symbol.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜