# Drag and drop z order

**URL:** <https://forum.kirupa.com/t/drag-and-drop-z-order/42210>\
**Category:** Uncategorized\
**Created:** [February 6, 2004, 1:32pm UTC](https://forum.kirupa.com/t/drag-and-drop-z-order/42210 "2004-02-06T13:32:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![souljunta](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@souljunta](https://forum.kirupa.com/u/souljunta)\
**Post date:** [February 6, 2004, 1:32pm UTC](https://forum.kirupa.com/t/drag-and-drop-z-order/42210/1 "2004-02-06T13:32:38Z")

</div>

Hi there

I’m new to the forum so firstly helllo

I’m trying to create a reasonable simple drag and drop animation when the user can grab different coloured square around the stage.

The problem is I want to have the animation so when they click on eack individual square it pops to the top of the z order (the forground) and then on release returns to it’s original postion in the animations z-order (layers)

Any ideas on how to code this ?

---

<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:** [February 6, 2004, 1:44pm UTC](https://forum.kirupa.com/t/drag-and-drop-z-order/42210/2 "2004-02-06T13:44:02Z")

</div>

I’ve just found the swap depth tutorial on this which explains some of my problem but not how to make the square return to their original z value once released. Any ideas on 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:** [February 6, 2004, 2:24pm UTC](https://forum.kirupa.com/t/drag-and-drop-z-order/42210/3 "2004-02-06T14:24:39Z")

</div>

think it goes something like this???

on (press) {  
startDrag(this);  
this.swapDepths(100);  
}  
on (release) {  
stopDrag();  
if (this.\_droptarget=="/target2") {  
setProperty(this, \_x, 444.8);  
setProperty(this, \_y, 249.5);  
} else {  
setProperty(this, \_x, 341.5); --\> origin position  
setProperty(this, \_y, 193.0); --\>Origin position  
}  
}

---

<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:** [February 6, 2004, 3:35pm UTC](https://forum.kirupa.com/t/drag-and-drop-z-order/42210/4 "2004-02-06T15:35:25Z")

</div>

cheers i’ll give that a try 🙂

do I need to add anything else in to make it work ?

---

<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:** [February 6, 2004, 5:47pm UTC](https://forum.kirupa.com/t/drag-and-drop-z-order/42210/5 "2004-02-06T17:47:53Z")

</div>

basically what u want is that when it drags and chooses a wrong answer, its goes back to its original position right…

If it is the case, then the above codes should be correct…
