# Creating a matrix of squares with a for loop

**URL:** <https://forum.kirupa.com/t/creating-a-matrix-of-squares-with-a-for-loop/254771>\
**Category:** flash\
**Created:** [March 15, 2008, 1:39am UTC](https://forum.kirupa.com/t/creating-a-matrix-of-squares-with-a-for-loop/254771 "2008-03-15T01:39:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![clot](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@clot](https://forum.kirupa.com/u/clot)\
**Post date:** [March 15, 2008, 1:39am UTC](https://forum.kirupa.com/t/creating-a-matrix-of-squares-with-a-for-loop/254771/1 "2008-03-15T01:39:39Z")

</div>

ok. I have a tricky question although the solution is likely staring me right in the face.

I want to create a bunch of squares appear in a grid-like fashion but not row by row. I’d like more of a diagonal effect.

Here’s the code I have so far:

```auto

runCubes = function(){
        for(i=0; i<21; i++){
            this.createEmptyMovieClip("cube"+i,this.getNextHighestDepth());        
            this["cube"+i]._alpha = 0;        
            this["cube"+i].attachMovie("cube","cube",this.getNextHighestDepth());
            this["cube"+i]._y = 130;
            this["cube"+i]._x = ((this["cube"+i]._x+45) * i);        
            this["cube"+i].tween("_alpha",30,1,"easeOutQuint",0.25*i);        
        }
        for(z=0; z<11; z++){
            this.createEmptyMovieClip("cube2"+z,this.getNextHighestDepth());        
            this["cube2"+z]._alpha = 0;        
            this["cube2"+z].attachMovie("cube","cube",this.getNextHighestDepth());
            this["cube2"+z]._y = (130+((this["cube2"+z]._y+45) * z));        
            this["cube2"+z].tween("_alpha",30,1,"easeOutQuint",0.25*z);
        }    
}

```

So this sort of works in the sense of it creates a vertical row and a horizontal row. But I need it to actually kind of ‘wipe’ diagonally across the page.

Can anyone offer any insight?

I’m kind of thinking I need to nest that in a couple more loops but I’m getting confused as to how I should do it. Thanks in advance!
