Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse over while dragging object in Flash CS5

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?

like image 640
CodeMouse92 Avatar asked Nov 23 '11 03:11

CodeMouse92


2 Answers

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.

like image 69
felipemaia Avatar answered Oct 13 '22 22:10

felipemaia


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

like image 45
Shedokan Avatar answered Oct 13 '22 22:10

Shedokan