I have a movieclip I’m dragging and dropping. When I drag the clip outside of the stage, it gets stuck in drag mode and when I bring the cursor back onto the stage it suddenly snaps back onto the cursors position and it continues to drag (basically screwing up my drag and drop sequence). What I’d like is for the clip to stop dragging and snap back to its original X and Y position whenever you drag it outside the SWFs stage. I tried to achieve this by adding a listener to the stage to listen for a MOUSE_UP event when the drag begins. But its not working and I keep getting errors.
Here is my code, it’s all contained in a document class:
//Add Event Listeners to MovieClip that is dragged
alarmLrg_mc.buttonMode = true;
alarmLrg_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragClip);
alarmLrg_mc.addEventListener(MouseEvent.MOUSE_UP, dropClip);
//Start the drag
private function dragClip(event:MouseEvent):void
{
_dragX = event.currentTarget.x;
_dragY = event.currentTarget.y;
event.currentTarget.startDrag();
event.currentTarge.parent.stage.addEventListener(MouseEvent.MOUSE_UP, dropClip);
event.currentTarget.parent.addChild(event.currentTarget);
}
//Stops the drag
private function dropClip(event:MouseEvent):void
{
_dropX = event.currentTarget.x;
_dropY = event.currentTarget.y;
event.currentTarget.stopDrag();
event.currentTarge.parent.removeEventListener(MouseEvent.MOUSE_UP, dropClip);
evalDrop(event.currentTarget.area_btn, event.currentTarget._iconType);
}
//Evaluates if the dragged clip landed on the hit area
private function evalDrop(clip:*, type:*):void
{
var clipType:String = type;
if (clip.hitTestObject(aptPlan_mc.dropzome_mc)){
clip.alpha = 0;
clip.parent.x = _dragX;
clip.parent.y = _dragY;
placeIcon(clipType);
}
else {
trace("didn't hit drop zone");
clip.alpha = 1;
clip.parent.x = _dragX;
clip.parent.y = _dragY;
}
}
When I test the file as is I get this Error:
ReferenceError: Error #1069: Property stopDrag not found on flash.display.Stage and there is no default value.
at Step2/dropClip()
Which I don’t understand because dropClip isn’t a property its a function. If anyone can explain how I need to modify my code to make the clip stop dragging or if I can constrain the drag so you can’t drag it outside the stage in the first place that could perhaps work as well. Thanks in advance!