# Swap depth of Movieclip based on Y location

**URL:** <https://forum.kirupa.com/t/swap-depth-of-movieclip-based-on-y-location/311634>\
**Category:** flash\
**Created:** [July 13, 2010, 2:31am UTC](https://forum.kirupa.com/t/swap-depth-of-movieclip-based-on-y-location/311634 "2010-07-13T02:31:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naezo](https://avatars.discourse-cdn.com/v4/letter/n/b782af/32.png) [@Naezo](https://forum.kirupa.com/u/Naezo)\
**Post date:** [July 13, 2010, 2:31am UTC](https://forum.kirupa.com/t/swap-depth-of-movieclip-based-on-y-location/311634/1 "2010-07-13T02:31:00Z")

</div>

Alright, I’m sorry for bugging you people with so many questions, but, I can’t seem to find the answer anywhere…

So I had asked the same question for AS2 how to do this and I received the code:

```auto
moviclip.swapDepths(movieclip._y);

```

and it worked perfectly.

but I decided that I wanted to continue the development of the game in AS3 (so that it will be more up to date and I could learn the new syntax), and I found the equivalent to swapDepths is setChildIndex. so I followed the new rules and came up with this code:

```auto

    setChildIndex(character_mc, character_mc.y);

```

but, sadly it does not work the same. the game becomes extremely laggy and almost unresponsive, but becomes normal again if I remove the code. So, my question is how can I add a similar code for this to work properly.

Thanks in advance,  
Naezo
