# Grids with for loops

**URL:** https://forum.kirupa.com/t/grids-with-for-loops/260828
**Category:** Uncategorized
**Created:** [May 20, 2008, 10:18am UTC](https://forum.kirupa.com/t/grids-with-for-loops/260828 "2008-05-20T10:18:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sci](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@sci](https://forum.kirupa.com/u/sci)
#### Post date: [May 20, 2008, 10:18am UTC](https://forum.kirupa.com/t/grids-with-for-loops/260828/1 "2008-05-20T10:18:15Z")

</div>

Hello all,

Pretty basic stuff this, but I’m not sure why it isn’t working.  
I have a movie clip in library which I want to attach to the stage multiple times to form a perfect grid. I am using th following code but it is only laying the movieclips out on the x axis:

for (var y:Number = 0; y\< 100; y = y + 10){  
for(var x:Number = 0; x \< 100; x = x + 10){  
this.attachMovie(“mc\_circle”, “mc\_circle” + x, x,{\_x:x, \_y:y});  
}  
}

Any ideas why this isn’'t working?

thanks

---

<div class="post-metadata">

### Author: ![sci](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@sci](https://forum.kirupa.com/u/sci)
#### Post date: [May 20, 2008, 1:06pm UTC](https://forum.kirupa.com/t/grids-with-for-loops/260828/2 "2008-05-20T13:06:10Z")

</div>

[http://www.kirupa.com/developer/actionscript/grid.htm](http://www.kirupa.com/developer/actionscript/grid.htm)

I need to duplicate the clip don’t I! Doh.

---

<div class="post-metadata">

### Author: ![neilmmm](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@neilmmm](https://forum.kirupa.com/u/neilmmm)
#### Post date: [May 20, 2008, 6:54pm UTC](https://forum.kirupa.com/t/grids-with-for-loops/260828/3 "2008-05-20T18:54:36Z")

</div>

there are many ways to do this

i prefer attachMovie - using a method like this … although i would normally attach to emptyMovie clip so i can scale or move the grid as i wish

```auto
for (i=0; i<10; i++) {
 for (h=0; h<10; h++) {
  var mc:MovieClip = this.attachMovie("circle_mc", "circle_mc"+this.getNextHighestDepth(), this.getNextHighestDepth());
  mc._x = i*mc._width;
  mc._y = h*mc._height;
 }
}

```

---

<div class="post-metadata">

### Author: ![sci](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@sci](https://forum.kirupa.com/u/sci)
#### Post date: [May 21, 2008, 12:54pm UTC](https://forum.kirupa.com/t/grids-with-for-loops/260828/4 "2008-05-21T12:54:08Z")

</div>

Hey thanks

So simple when you have been shown how. I agree that the attachMovie method is better… I didn’t really want unused instances laying around off the stage. Thanks again.

---

<div class="post-metadata">

### Author: ![neilmmm](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@neilmmm](https://forum.kirupa.com/u/neilmmm)
#### Post date: [May 21, 2008, 4:21pm UTC](https://forum.kirupa.com/t/grids-with-for-loops/260828/5 "2008-05-21T16:21:56Z")

</div>

yw
