I’m building a simple little drag and drop game and I’m having some troubles with the movie clips return to the original position. The user can drag a movie clip to a target, and it will show something in another movie clip, and when the user moves their mouse away from the target area, then the dragged movie clip should return to it’s original position.
The trouble I’m having is that when the it does this only once. Afterwards, when I drag the movieclips again, they don’t want to be moved from that specific area (still draggable), but like limiited to where it doesn’t snap to the center drop target again. If anybody could help me with this I’ll be so grateful!
My Code:
stop();
function dragSetup(clip, targ) {
clip.onPress = function() {
startDrag(this);
this.beingDragged=true;
};
clip.onRelease = clip.onReleaseOutside=function () {
stopDrag();
this.beingDragged=false;
if (eval(this._droptarget) == targ) {
this.onTarget = true;
switch(clip._name) {
case "drag1":
answer.gotoAndStop(2);
break;
case "drag2":
answer.gotoAndStop(3);
break;
case "drag3":
answer.gotoAndStop(4);
break;
case "drag4":
answer.gotoAndStop(5);
break;
case "drag5":
answer.gotoAndStop(6);
break;
}
} else {
this.onTarget = false;
answer.gotoAndStop(1);
}
};
clip.myHomeX = clip._x;
clip.myHomeY = clip._y;
clip.myFinalX = targ._x;
clip.myFinalY = targ._y;
clip.onEnterFrame = function() {
if (!this.beingDragged && !this.onTarget) {
this._x -= (this._x-this.myHomeX)/5;
this._y -= (this._y-this.myHomeY)/5;
} else if (!this.beingDragged && this.onTarget) {
this._x -= (this._x-this.myFinalX)/5;
this._y -= (this._y-this.myFinalY)/5;
clip.onRollOut = function() {
this.onEnterFrame = function() {
this._x -= (this._x-this.myHomeX)/5;
this._y -= (this._y-this.myHomeY)/5;
}
answer.gotoAndStop(1);
}
}
};
}