Swap depth of Movieclip based on Y location

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:

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:


    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