views:

33

answers:

4

I have a draggable item, a MovieClip that calls startDrag() on itself when it is clicked, and another MovieClip on the stage.

I need the MovieClip to receive ROLL_OVER and ROLL_OUT events while the draggable MovieClip is being dragged over it, but the lower clip doesn't receive these messages while a clip is being dragged over it.

Essentially, ROLL_OVER is only sent to the topmost MovieClip under the mouse. Normally, you'd fix that with some combination of mouseEnabled or mouseChildren on the overlapping MovieClips, but if you do that to a draggable MovieClip, it breaks dragging. I need to detect when the mouse is over the lower MovieClip, regardless of what MovieClips are above it.

So, how do I do that?

A: 

use the MOUSE_OVER mouse event.

TheDarkInI1978
Thanks for the suggestion, but this won't work in my situation, because, just like ROLL_OVER, MOUSE_OVER doesn't fire on objects if there is a display object above it that doesn't have mouseEnabled set to false.
cc
A: 

You could use the hitTestObject() method

It's a bit overkill :) but you also could use Collision detection
http://coreyoneil.com/portfolio/index.php?project=5

PatrickS
+1  A: 

You could disable mouse interaction for the clip that is being dragged eg.
On your MOUSE_DOWN event:

displayObject.startDrag();
// Disable mouse interactions for this object
displayObject.mouseEnabled = false;
// Disable mouse interactions for this objects children.
displayObject.mouseChildren = false;

Then in your MOUSE_UP event where you call stopDrag() you can enable it again:

displayObject.mouseEnabled = true;
displayObject.mouseChildren = true;

I haven't tried this but it should stop the clip that you are dragging from receiving any mouse events.

*Just one thing though is that since the clip itself doesn't receive mouse events, the MOUSE_UP event cannot be placed directly onto it but will have to be placed on it's parent or the stage.

cmann
This solved it. Thank you very much! The solutions by PatrickS and www0z0k would also work, but they are more complicated. This is the simple solution, since you just need to track "am I being dragged" and attach the mouseUp to the stage.
cc
A: 

declare a function that checks if mouse coordinates are inside the movieclip rectangle

when calling startDrag() add ENTER_FRAME event listener to the clip on the stage and use that function as a listener

when calling stopDrag() - remove the listener

www0z0k