How do I detect rollover on elements while dragging a MovieClip above them?
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 topmo开发者_运维百科st 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?
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.
use the MOUSE_OVER mouse event.
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
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
精彩评论