Newby to Flash -- need help with Drag and Drop
I have been trying to create a drag and drop in Flash where I have five different places for an instance of a mc to be dropped. I want to be able to drop only three instances to each place and these three instances are specific to one of the five "drop places". I also want the mc instance to go back to its original position if it is not dropped on the right place. I've got the actionscript working to drag and drop the mc instances on the "drop places" but I cannot figure out how to do the if statements so that if it doesn't match the correct drop place it will go back to its original position.
Here's some of my code:
Analyze1_mc.objName = "Analyze1";
Analyze1_mc.val = 1;
Design1_mc.objName = "Design1";
Design1_mc.val = 4;
Analyze1_mc.buttonMode = true; // sets mouse pointer to hand
Design1_mc.buttonMode = true;
Analyze1_mc.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
Analyze1_mc.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
Design1_mc.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
Design1_mc.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
var originalPosition:Point;
function returnToOriginalPosition(): void
{
originalPosition = new Point(x,y)
x = originalPosition.x;
y = originalPosition.y;
}
// function to drag item clicked
function fl_ClickToDrag(event:MouseEvent):void
{
event.currentTarget.startDrag();
event.target.parent.addChild(event.target);
}
function fl_ReleaseToDrop(event:MouseEvent):void
{
var target:MovieClip = event.currentTarget as MovieClip;
var item:MovieClip = MovieClip(event.target);
item.stopDrag();
if (event.target.hitTestObject(AnalyzeTarget_mc) && (event.target.val == 1)) {
trace ("Analyze1");
event.target.x = AnalyzeTarget_mc.x + 42;
event.target.y = AnalyzeTarget_mc.y + 5;
updateItem(Analyze1_mc);
} else {
returnToOriginalPosition();
}
if (event.target.hitTestObject(DesignTarget_mc) && (event.target.val == 4)) {
trace ("Design1");
event.target.x = DesignTarget_mc.x + 42;
event.target.y = DesignTarget_mc.y + 5;
updateItem(Design1_mc);
} else {
returnToOriginalPosition();
}
function updateItem(item:MovieClip):void {
buttonMode = false;
removeEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
}
I put the trace in to check the function -- and I do get the output when the mc instance is dropped on the right place -- but there is no return to original position if the instance is dropped in the wrong spot and there is no update to the mc instance.
Any help would be greatly appreciated. Thanks!
