AS2 - Duplicate movieClip, and send it to back

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;



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.

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?

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).

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.

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.


Works smoothly now. :smile: Thank you for the advice.

1 Like