# Random drag and drop

**URL:** <https://forum.kirupa.com/t/random-drag-and-drop/58628>\
**Category:** Uncategorized\
**Created:** [July 24, 2004, 7:19am UTC](https://forum.kirupa.com/t/random-drag-and-drop/58628 "2004-07-24T07:19:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cappucino](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@cappucino](https://forum.kirupa.com/u/cappucino)\
**Post date:** [July 24, 2004, 7:19am UTC](https://forum.kirupa.com/t/random-drag-and-drop/58628/1 "2004-07-24T07:19:25Z")

</div>

hi everyone!!

i have this problem about drag and drop. i have six pictures which should be able to drag and drop randomly at the six initialize drop targets. I only able to drag the first picture to only one drop target correctly. let say i drag ‘picture1’ and drop at ‘target2’…and ‘picture2’ will automatically occupy ‘target1’ where ‘picture1’ resides previously. but when i drag ‘picture1’ (now resides at ‘target2’) to ‘target6’, ‘picture6’ will go to reside at ‘target1’…actually it should reside at ‘target2’. i still have no idea how to do the random drag and drop…hope i’ll get solutions from you all!!

thanks in advance.

---

<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:** [July 24, 2004, 11:54am UTC](https://forum.kirupa.com/t/random-drag-and-drop/58628/2 "2004-07-24T11:54:22Z")

</div>

If the pictures are the same size, rather than complicating matters with targets, you could just get the pictures to switch x and y values if one is dropped on the other. With the way you are doing it each picture will have to remember which target it is currently on… I don’t know how to do that!

---

<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:** [July 26, 2004, 1:50am UTC](https://forum.kirupa.com/t/random-drag-and-drop/58628/3 "2004-07-26T01:50:15Z")

</div>

hi insomniac…here’s my coding for the first dragable picture named ‘drop1’…the pictures are all in the same size…the six drop targets are movieclip and named them ‘target’…so that if the ‘drop1’ is placed randomly at the targets…it will get the target’s x and y coordinates…i’m not sure if this is the correct way of writing the condition…but the coding doesn’t work. ☹

on (press) {  
\_alpha = 20;  
this.startDrag();  
}  
on (release, releaseOutside) {  
\_alpha = 100;  
stopDrag();  
if (this.\_droptarget == “/target”) {  
this.\_x = \_root.target.\_x;  
this.\_y = \_root.target.\_y;

```
	_root.drop2._x = _root.target._x;
	_root.drop2._y = _root.target._y;
} 
else if (this._droptarget == "/target") {
	this._x = _root.target._x;
	this._y = _root.target._y;
	
	_root.drop3._x = _root.target._x;
	_root.drop3._y = _root.target._y;
}
else if (this._droptarget == "/target") {
	this._x = _root.target._x;
	this._y = _root.target._y;
	
	_root.drop4._x = _root.target._x;
	_root.drop4._y = _root.target._y;
}
else if (this._droptarget == "/target") {
	this._x = _root.target._x;
	this._y = _root.target._y;
	
	_root.drop5._x = _root.target._x;
	_root.drop5._y = _root.target._y;
}
else if (this._droptarget == "/target") {
	this._x = _root.target._x;
	this._y = _root.target._y;
	
	_root.drop6._x = _root.target._x;
	_root.drop6._y = _root.target._y;
} 
//go back to original place
else if (this._droptarget == "/target") {
	this._x = _root.target._x;
	this._y = _root.target._y;
	
	_root.drop1._x = _root.target._x;
	_root.drop1._y = _root.target._y;
}

```

}

---

<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:** [July 26, 2004, 4:49am UTC](https://forum.kirupa.com/t/random-drag-and-drop/58628/4 "2004-07-26T04:49:25Z")

</div>

i’ve found the solution to my problem…now i am able to do the random drag and drop 🙂

the link to the tutorial is:  
[http://www.flashkit.com/tutorials/Actionscripting/Drag\_Dr-Gorky-126/index.php](http://www.flashkit.com/tutorials/Actionscripting/Drag_Dr-Gorky-126/index.php)

---

<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:** [July 26, 2004, 9:05am UTC](https://forum.kirupa.com/t/random-drag-and-drop/58628/5 "2004-07-26T09:05:44Z")

</div>

that’s pretty cool, nice one
