# duplicateMovieClip into rows and columns

**URL:** <https://forum.kirupa.com/t/duplicatemovieclip-into-rows-and-columns/14090>\
**Category:** flash\
**Created:** [February 21, 2003, 8:22pm UTC](https://forum.kirupa.com/t/duplicatemovieclip-into-rows-and-columns/14090 "2003-02-21T20:22:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![markP](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@markP](https://forum.kirupa.com/u/markP)\
**Post date:** [February 21, 2003, 8:22pm UTC](https://forum.kirupa.com/t/duplicatemovieclip-into-rows-and-columns/14090/1 "2003-02-21T20:22:25Z")

</div>

how would I do this?

duplicate a movie clip, let’s say 15 times, and after the 5th clip a new column is created, on up to the 15 clips making 3 total columns of 5?

Thanks

---

<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:** [February 21, 2003, 8:49pm UTC](https://forum.kirupa.com/t/duplicatemovieclip-into-rows-and-columns/14090/2 "2003-02-21T20:49:59Z")

</div>

MX I presume?

what youd do is use loops. One loop to loop through your columns, and one to loop through your rows. On the first loop going through a column, you loop through your rows so that first column position is populated with the number of rows you have. So one loop goes up and down and the other accross, making the grid.

In order to actually space out your grid, you need to base your poisition on your grid position (row/column) and a spacing value. Heres an example:

```auto

spacing = 10;
depth = 0
for (x = 0; x < 3; x++){
	for (y = 0; y < 5; y++){
		this.attachMovie("clip", "clip"+depth, depth++, {_x:x*spacing, _y:y*spacing})
	}
}

```

this sets clips attached clips ffrom the library item “clip” 10 pixels apart in a 3 (wide) by 5 (down) column. The argument after the depth is the init object which lets you set properties for the newly attached clip, in this case we are setting the \_x and \_y to be the x and y values of the loops (each looping through a succesively higher number) times the spacing which spaces it out along a grid.

---

<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:** [February 21, 2003, 9:34pm UTC](https://forum.kirupa.com/t/duplicatemovieclip-into-rows-and-columns/14090/3 "2003-02-21T21:34:13Z")

</div>

Yea… that’s pretty cool. I thought it was something like that but I didn’t know how to write it (I had my second for loop in the wrong spot). I’m going to mess with it a little bit. I need to make it duplicate a movieclip for each childNode it finds in an XML doc and make as many columns of 5 as it needs to complete the task. So I need to get the “3” you have for the X to be dynamic somehow. Can i use length of the total children divided by 5 to get that number?

---

<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:** [February 21, 2003, 9:45pm UTC](https://forum.kirupa.com/t/duplicatemovieclip-into-rows-and-columns/14090/4 "2003-02-21T21:45:17Z")

</div>

yeah you can replace 3 with anything you want. I dont know what the dividing by 5 does though?

---

<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:** [February 22, 2003, 1:15pm UTC](https://forum.kirupa.com/t/duplicatemovieclip-into-rows-and-columns/14090/5 "2003-02-22T13:15:32Z")

</div>

By dividing the total number childNode.length (10) by how many movieclips I want in a column (5) I’ll get how many columns I need (2). These are just numbers I’m pulling out of the air right now so I obviously wouldn’t need to calculate it like thisfor static numbers. But as that XML childNode number grows so must the number of columns, hence the dividing by 5.

Thanks Senocular
