# \[AS\] drag and drop; return to original pos

**URL:** <https://forum.kirupa.com/t/as-drag-and-drop-return-to-original-pos/64652>\
**Category:** Uncategorized\
**Created:** [September 18, 2004, 1:01pm UTC](https://forum.kirupa.com/t/as-drag-and-drop-return-to-original-pos/64652 "2004-09-18T13:01:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rockit](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@rockit](https://forum.kirupa.com/u/rockit)\
**Post date:** [September 18, 2004, 1:01pm UTC](https://forum.kirupa.com/t/as-drag-and-drop-return-to-original-pos/64652/1 "2004-09-18T13:01:53Z")

</div>

Hi, if anyone can help with this as its driving me nuts! Trying to build a drag and drop navigation, all the drag and drop works great, the test for the hit works ie if its on the target it centers the drag clip over the target, if its of the target the drag clip returns to its start postion. What I cannot get right is the code to check if the target already has a clip on it, if it has that clip needs to return to its start position, so we only ever have one drag clip on the target.

code timeline:  
[color=red]//  
// initialize vars  
left = 10;  
right = 500;  
top = 10;  
bottom = 380;  
speed = 10;  
targetX = targetSpot\_mc.\_x;  
targetY = targetSpot\_mc.\_y;  
//  
// test movieclip position  
function targetTest(myClip) {  
if (myClip.hitTest(targetSpot\_mc)) {  
myClip.onTarget = true;  
} else {  
myClip.onTarget = false;  
}  
}  
//  
// move movieClip to target pos.  
function moveToTarget(myClip) {  
myClip.\_x -= (myClip.\_x-targetX)/speed;  
myClip.\_y -= (myClip.\_y-targetY)/speed;  
}  
//  
// move movieClip to start pos.  
function moveToStart(myClip) {  
myClip.\_x -= (myClip.\_x-myClip.homeX)/speed;  
myClip.\_y -= (myClip.\_y-myClip.homeY)/speed;  
}  
//  
// button 1  
home\_mc.onMouseDown = function() {  
mousePressed = true;  
};  
home\_mc.onMouseUp = function() {  
mousePressed = false;  
};  
home\_mc.onPress = function() {  
startDrag(this, false, left, top, right, bottom);  
};  
home\_mc.onRelease = home\_mc.onReleaseOutside=function () { stopDrag();targetTest(this);};  
home\_mc.onEnterFrame = function() {  
if (mousePressed == false && this.onTarget == false) {  
moveToStart(this);  
} else if (mousePressed == false && this.onTarget == true) {  
moveToTarget(this);  
}  
};  
//  
// button 2  
info\_mc.onMouseDown = function() {  
mousePressed = true;  
};  
info\_mc.onMouseUp = function() {  
mousePressed = false;  
};  
info\_mc.onPress = function() {  
startDrag(this, false, left, top, right, bottom);  
};  
info\_mc.onRelease = info\_mc.onReleaseOutside=function () { stopDrag();targetTest(this);};  
info\_mc.onEnterFrame = function() {  
if (mousePressed == false && this.onTarget == false) {  
moveToStart(this);  
} else if (mousePressed == false && this.onTarget == true) {  
moveToTarget(this);  
}  
};[/color]

[color=black]code on drag clips button 1 and 2:[/color]  
[color=red]onClipEvent (load) {  
// initialize start position  
homeX = this.\_x;  
homeY = this.\_y;  
}[/color]

[color=black]thanks in advance and big thanks to everyone on this forum as its a godsend for getting your head round flash.[/color]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 18, 2004, 5:22pm UTC](https://forum.kirupa.com/t/as-drag-and-drop-return-to-original-pos/64652/2 "2004-09-18T17:22:48Z")

</div>

Hi, got it now, found a few similiar posts. The functions for moving the clips changed to prototypes and added a var for each drag clip to check for in a loop, if its not the same as my current drag clip then it calls the moveToStart reset function… looking at the code above and what I have now I think I was miles off! even though the first code worked…was I going in wrong direction with the above code or? would like to know!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 19, 2004, 2:47pm UTC](https://forum.kirupa.com/t/as-drag-and-drop-return-to-original-pos/64652/3 "2004-09-19T14:47:38Z")

</div>

hi rockit, can you link me to that post or send my the fla
