Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag & drop - snap to original position

Status
Not open for further replies.

Whiteybags

Technical User
May 18, 2004
18
IE
Hi,
I'm trying to do drag & drop. I have the drag working. I'm getting the feedback from trace letting me know when my movie clips hit the targets & which ones.
I cannot get my movie clips to snap back to the original position if they do not hit a target. That is what I'm trying to find out.

I have a movie clip (clip1) and a button within the movie clip. My target areas are numbered 1 to 4 (target1). The following code is on the button.



on (press) {
this.startDrag (false);
}

on (release) {
this.stopDrag();

if (_root.clip1._droptarget == "/target1") {
trace ("clip 1 in target 1");
}
if (_root.clip1._droptarget == "/target2") {
trace ("clip 1 in target 2");
}
if (_root.clip1._droptarget == "/target3") {
trace ("clip 1 in target 3");
}
if (_root.clip1._droptarget == "/target4") {
trace ("clip 1 in target 4");
}
else {
this_y= OrgY;
this_x= OrgX;
}
}


Please help :)
 
You just need to set up the original position when the clip is clicked on:

Code:
on (press) { 
this.startDrag (false); 
this.orgX=this._x
this.orgY=this._y
} 

on (release) { 
this.stopDrag(); 

if (_root.clip1._droptarget == "/target1") { 
trace ("clip 1 in target 1"); 
} 
if (_root.clip1._droptarget == "/target2") { 
trace ("clip 1 in target 2"); 
} 
if (_root.clip1._droptarget == "/target3") { 
trace ("clip 1 in target 3"); 
} 
if (_root.clip1._droptarget == "/target4") { 
trace ("clip 1 in target 4"); 
} 
else { 
this._y= this.orgY; 
this._x= this.orgX; 
} 
}
 
Figured it out...problem with if statements...need if else. Also need the co-ordinates for all the movie clip...the areas for them to stay at or snap back to.

Thanks for your help!
Heres what I was left with:


on (press) {
this.startDrag ();
}

on (release) {
this.stopDrag();

if (_root.clip1._droptarget == "/target1") {
this._x=162;
this._y=233;
}

else if (_root.clip1._droptarget == "/target2") {
this._x=217;
this._y=233;
}

else if (_root.clip1._droptarget == "/target3") {
this._x=273;
this._y=233;
}

else if (_root.clip1._droptarget == "/target4") {
this._x=329;
this._y=233;
}
else {
this._x=103;
this._y=28;
}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top