Get object under mouse

Jorjon picture Jorjon · Sep 16, 2009 · Viewed 7.3k times · Source

Is there a way to get the current object(s) under the mouse? There's a function called getObjectsUnderPoint() on AS3, but I need to know if AS2 provides a similar functionality. In case it doesn't, anyone has a good implementation of what I am trying to achieve?

Migrating to AS3 is not an option.

Thanks!

Answer

Daniel picture Daniel · Oct 22, 2009

getObjectsUnderPoint returns an Array of objects on an object under the given point.

I wrote this condition to check if the mouse is over any object on a certain layer.

if (mySprite.getObjectsUnderPoint(new Point(mouseX, mouseY)).length) 
{
    return;
}
else
{
    doSomething();
}

You could also use stage.getObjectsUnderPoint for a global check.

Hope this helps.

Migrating to AS3 is not an option. Nevermind...