obr
02-02-2009, 09:22 PM
Hello,
I'm pretty much a novice at actionscript so bear with me.
I've got 6 draggable movie clips
that snap to a target - which works fine. If they don't hit the target area they snap back to their starting point- which also works fine.
My problem is that they can all be dragged to the target one after another, but I only want one movieclip to be at the target at any one time.
So,when I start dragging a new clip toward the target I want the movieclip thats already on the target to reset itself to it's starting position, thus being replaced by the incoming clip.
I want this to happen for all the draggable clips.
I'm real stuck.
this is the working bit that I've got so far - any advice with what I need to add will be most welcome.
ta.
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;
this.gotoAndStop(2);
;
} else {
this.onTarget = false;
this.gotoAndStop(1);
}
};
//the variables below store the clips starting position
clip.myHomeX = clip._x;
clip.myHomeY = clip._y;
//the variables below store the clips end position
clip.myFinalX = targ._x;
clip.myFinalY = targ._y;
clip.onEnterFrame = function() {
//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)
// then move the MC back to its original starting point"
if (!this.beingDragged && !this.onTarget) {
this._x -= (this._x-this.myHomeX);
this._y -= (this._y-this.myHomeY);
//if the circle is dropped on any part of the target it slides to the center of the target (with a smooth motion)
} else if (!this.beingDragged && this.onTarget) {
this._x -= (this._x-this.myFinalX)/2;
this._y -= (this._y-this.myFinalY)/2;}
}
};
}
dragSetup(circle_mc,targetCircle);
dragSetup(circle2_mc,targetCircle);
dragSetup(circle3_mc,targetCircle);
dragSetup(circle4_mc,targetCircle);
dragSetup(circle5_mc,targetCircle);
dragSetup(circle6_mc,targetCircle);
I'm pretty much a novice at actionscript so bear with me.
I've got 6 draggable movie clips
that snap to a target - which works fine. If they don't hit the target area they snap back to their starting point- which also works fine.
My problem is that they can all be dragged to the target one after another, but I only want one movieclip to be at the target at any one time.
So,when I start dragging a new clip toward the target I want the movieclip thats already on the target to reset itself to it's starting position, thus being replaced by the incoming clip.
I want this to happen for all the draggable clips.
I'm real stuck.
this is the working bit that I've got so far - any advice with what I need to add will be most welcome.
ta.
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;
this.gotoAndStop(2);
;
} else {
this.onTarget = false;
this.gotoAndStop(1);
}
};
//the variables below store the clips starting position
clip.myHomeX = clip._x;
clip.myHomeY = clip._y;
//the variables below store the clips end position
clip.myFinalX = targ._x;
clip.myFinalY = targ._y;
clip.onEnterFrame = function() {
//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)
// then move the MC back to its original starting point"
if (!this.beingDragged && !this.onTarget) {
this._x -= (this._x-this.myHomeX);
this._y -= (this._y-this.myHomeY);
//if the circle is dropped on any part of the target it slides to the center of the target (with a smooth motion)
} else if (!this.beingDragged && this.onTarget) {
this._x -= (this._x-this.myFinalX)/2;
this._y -= (this._y-this.myFinalY)/2;}
}
};
}
dragSetup(circle_mc,targetCircle);
dragSetup(circle2_mc,targetCircle);
dragSetup(circle3_mc,targetCircle);
dragSetup(circle4_mc,targetCircle);
dragSetup(circle5_mc,targetCircle);
dragSetup(circle6_mc,targetCircle);