Get the object under the mouse

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

Moving to AS3 is not an option.

Thank!

+2


source to share


2 answers


You can do it automatically with AS2, but it only gets the topmost object.

This is done using the _droptarget property for movie clips. What you are doing is to make an empty MovieClip, run startDrag on it with lockCenter set to true. Then you stop Drag and look at this _droptarget property.



The only other way to do this would be to manually iterate over the clips and use the hitTest method.

+2


source


getObjectsUnderPoint returns an array of objects to the object below the given point.

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

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

      



You can also use stage.getObjectsUnderPoint for global validation.

Hope it helps.

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

+3


source







All Articles