# Duplicating movie clips

**URL:** <https://forum.kirupa.com/t/duplicating-movie-clips/7386>\
**Category:** flash\
**Created:** [October 29, 2002, 10:55pm UTC](https://forum.kirupa.com/t/duplicating-movie-clips/7386 "2002-10-29T22:55:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sorcerer](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@Sorcerer](https://forum.kirupa.com/u/Sorcerer)\
**Post date:** [October 29, 2002, 10:55pm UTC](https://forum.kirupa.com/t/duplicating-movie-clips/7386/1 "2002-10-29T22:55:53Z")

</div>

Is it possible to duplicate a movie clip within a movie clip in the same loop?

Lets say I have 2 MCs, Inside and Outside.

I have the Variable

NumOutside = 3 _this is the number of times the outside MC will be duplicated_

And the Array

NumInside[1] = 2 _this is the number of times that the Inside MC will be duplicated within Outside1_  
NumInside[2] = 1 _this is the number of times that the Inside MC will be duplicated within Outside2_  
NumInside[3] = 3 _this is the number of times that the Inside MC will be duplicated within Outside3_

Is there any way in my _for_ command to target  
\_root.Outside1 when I = 1 and duplicate Inside 2 times  
\_root.Outside2 when I = 2 and duplicate Inside 1 time  
\_root.Outside3 when I = 3 and duplicate Inside 3 times

I’ve tried the following code but have no way to reference the duplicated versions of Outside:

```auto
for (i=1;i!==NumOutside;i++){
	_root.Outside.duplicateMovieClip("Outside"+i,i);
	setProperty("_root.Outside"+i,_y,i*30);
	for (j=1;j!==NumInside*;j++){
		/* need something like _root.Outside+i+.Inside.duplicateMovieClip("Inside"+j,j); */
}

```

---

<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:** [October 30, 2002, 2:42am UTC](https://forum.kirupa.com/t/duplicating-movie-clips/7386/2 "2002-10-30T02:42:57Z")

</div>

duplicated clips appear on the same timeline as the clip they’re duplicating. you call it in such a way as to change that. you can approach the problem a little differently however.

one solution would be to put “inside” in “outside”. then you get one copy by default and duplicated clips will appear within “outside”.

another approach would be to use attachMovie rather than duplicateMovieClip. it’s a little more flexible in terms of where you put stuff.

---

<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:** [October 30, 2002, 7:39pm UTC](https://forum.kirupa.com/t/duplicating-movie-clips/7386/3 "2002-10-30T19:39:35Z")

</div>

I’m not sure if I understand you or if you understand me. The “Inside Movie Clip” is Located inside the “Outside Movie Clip” I am duplicating the Outside movie clip 3 times but inside each one of those duplicates I want to duplicate the Inside Movie Clip a different number of times so:

Outside1 contains Inside1 and Inside2  
Outside2 contains Inside1  
Outside3 contains Inside1, Inside2, and Inside3

what I am asking is how I duplicate the Inside clips within the duplicated outside clips without having to target each created clip individually. I would like to use a loop similar to the one I used to create the outside clips.

---

<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:** [October 30, 2002, 8:40pm UTC](https://forum.kirupa.com/t/duplicating-movie-clips/7386/4 "2002-10-30T20:40:58Z")

</div>

Nevermind, I figured it out. Dit it like this:

```auto
for (i=0;i!==OutsideNum;i++){
	_root.Outside.duplicateMovieClip("Outside"+i,i);
	setProperty("_root.Outside"+i,_y,i*30);
	for(j=0;j!==InsideNum*;j++){
		duplicateMovieClip("_root.Outside"+i+".Inside","Inside"+j,j+10)
		setProperty("_root.Outside"+i+".Inside"+j,_y,(25+(j*25)-(InsideNum**25)));
	}
	removeMovieClip("_root.Outside"+i+".Inside");
}
_root.Outside.removeMovieClip();

```

---

<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:** [October 31, 2002, 12:48am UTC](https://forum.kirupa.com/t/duplicating-movie-clips/7386/5 "2002-10-31T00:48:19Z")

</div>

aha, i didn’t get the part where you’d already put “inside” inside “outside”.

you can store a movie clip in a variable to avoid evaluating it each time (apparently a costly operation processor-wise).

you could amend your code to use this technique like so:

```auto

for (i=0; i < OutsideNum; i++){
	_root.Outside.duplicateMovieClip("Outside"+i,i);
	outerClip = _root["Outside"+i];
	outerClip._y = i*3;
	for(j=0; j < InsideNum*; j++){
		duplicateMovieClip(outerClip.Inside","Inside"+j,j+1);
		outerClip["Inside"+j]._y = 25+(j*25)-(InsideNum**25));
	}
	removeMovieClip(outerClip.Inside);
}
_root.Outside.removeMovieClip();

```
