views:

1129

answers:

2

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!

+1  A: 

You can sort of do this in an automated with AS2, but it only gets the top-most object.

This is done using to _droptarget property of movieclips. What you do is make a blank MovieClip, run startDrag on it with the lockCenter arugment set to true. Then you stopDrag and look at that clips _droptarget property.

The only other method of doing this would be to manually loop over your clips and use the hitTest method.

Branden Hall
Seems like iterating is the easier approach. Thanks.
Veehmot
+1  A: 

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...

Daniel
Thanks for your reply Daniel, but I'm working on ActionScript 2.
Veehmot