I have a project with Flash Professional CS5 and ActionScript 3.
I need to trigger an event when I drag an object over a particular spot, but haven't dropped it yet. Then, I need to trigger a different event when I leave that spot (still dragging). However, this should only occur while I am dragging on object.
The traditional mouse over and mouse leave events aren't working while dragging (only while not dragging).
How do I do this?
The reason it's not working is because the top DisplayObject (the one being dragged, is stealing the events for itself).
You have a few options, 1st is adding the MOUSE_MOVE event to the dragged object instead of the particular spot, and you could do a hitTestObject() to verify if they overlap, or a hitTestPoint() if the mouse is inside the particular spot.
So basically do this:
draggedObject.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
function onMouseMove(evt : MouseEvent) : void {
var particularSpot : MovieClip = MovieClip(evt.currentTarget.parent).getChildByName("particular spot object name");
if(particularSpot.hitTestPoint(evt.mouseX, evt.mouseY)) // or use hitTestObject
{
// The mouse is on top of particular object
}
else
{
// The mouse is not on top of particular object
}
}
Second one is to disable mouse events for the dragged object with mouseChildren
and mouseEnabled
properties, but that would break your current dragging, you would have to rearrange your events to the dragged object parent or the stage.
Simply call objectContainer.getObjectsUnderPoint(new Point(mouseX, mouseY))
and you'll get all objects under that point, and you can loop trough them and check if one of them is a `drop target.
See: Actionscript 3: get display object at pixel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With