# AS2 - Duplicate movieClip, and send it to back

**URL:** <https://forum.kirupa.com/t/as2-duplicate-movieclip-and-send-it-to-back/551207>\
**Category:** flash\
**Created:** [February 23, 2015, 5:33am UTC](https://forum.kirupa.com/t/as2-duplicate-movieclip-and-send-it-to-back/551207 "2015-02-23T05:33:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drud14](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drud14](https://forum.kirupa.com/u/Drud14)\
**Post date:** [February 23, 2015, 5:33am UTC](https://forum.kirupa.com/t/as2-duplicate-movieclip-and-send-it-to-back/551207/1 "2015-02-23T05:33:36Z")

</div>

I am building a Tic Tac Toe game where I duplicate a movieClip “oh” and it is placed on a Tic Tac Toe board by snapping it to a position.  
This works, however when it duplicates movieClip “oh”, it puts it on top of everything else. I need to have “oh” below another movieClip on the stage, “my\_mc”.

Here’s my code:

```
function pcturn() {
// lengthy game code omitted

duplicateMovieClip("oh", "oh"+tmp, tmp);

_root["oh"+tmp]._x = _root["rc"+tmp]._x;
_root["oh"+tmp]._y = _root["rc"+tmp]._y;

my_mc.swapDepths(getNextHighestDepth());
my_mc.swapDepths(+1000);
my_mc.swapDepths(oh);
oh.swapDepths(-1000);

}

```

None of the last four lines of code do not work. I need “oh” to go below “my\_mc”.

I’ve tried placing the _swapDepths_ code in an onEnterFrame function, on and inside my\_mc, and elsewhere in the main timeline, but nothing works to bring it to the top.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [February 23, 2015, 7:02am UTC](https://forum.kirupa.com/t/as2-duplicate-movieclip-and-send-it-to-back/551207/2 "2015-02-23T07:02:56Z")

</div>

If you call `getDepth` on the various elements that you’re trying to move around, do the values make sense?

Are all of the MovieClips direct children of `_root`?

> [@Drud14](#):
>
> I’ve tried placing the swapDepths code in an onEnterFrame function

That seems like it could be dangerous, since you’re eating up 1000 depths, it seems, per frame. Rather than just one or two when someone makes a tic-tac-toe move.

* * *

It also looks like you haven’t tried: `_root["oh" + tmp].swapDepths(my_mc)`.

> [@Drud14](#):
>
> None of the last four lines of code do not work. I need “oh” to go below “my\_mc”.

Really? From the rest of your post’s description, it sounds like you want `"oh" + tmp` to go below `my_mc`, because it’s the one that has been newly duplicated. Referencing `oh` by itself will target the old copy, not the new copy.

---

<div class="post-metadata">

**Author:** ![Drud14](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drud14](https://forum.kirupa.com/u/Drud14)\
**Post date:** [February 24, 2015, 4:14am UTC](https://forum.kirupa.com/t/as2-duplicate-movieclip-and-send-it-to-back/551207/3 "2015-02-24T04:14:20Z")

</div>

Thank you for the reply Krilnon.

I am a bit of a noob, and I did not realize that duplicated movieClips are given new names until I read your reply.

As they are duplicated, the movieClips are named like so: “oh11”, “oh12”, “oh13”, etc.

I changed my code to reflect the new names, and removed other unnecessary code that I had been trying.

```
oh11.swapDepths(-19);
ex11.swapDepths(-18);
oh12.swapDepths(-17);
ex12.swapDepths(-16);
oh13.swapDepths(-15);
//etc

```

Works smoothly now. 😄 Thank you for the advice.
