# Creating a grid

**URL:** https://forum.kirupa.com/t/creating-a-grid/118954
**Category:** Uncategorized
**Created:** [August 10, 2004, 2:09pm UTC](https://forum.kirupa.com/t/creating-a-grid/118954 "2004-08-10T14:09:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![fumeng](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@fumeng](https://forum.kirupa.com/u/fumeng)
#### Post date: [August 10, 2004, 2:09pm UTC](https://forum.kirupa.com/t/creating-a-grid/118954/1 "2004-08-10T14:09:06Z")

</div>

hi.

i’m creating a grid and i can place everything in nice columns but i cannot figure out how to create a new row. here’s the code i use:

```auto

var numColumns:Number = 7;
var columnWidth:Number = Stage.width/7;
var numRows:Number = 6;
var rowHeight:Number = Stage.height/6;
var firstDay:Number = 1;

for(i=0; i<= lastDay; i++){
	var dateClip = _root.createEmptyMovieClip("dateClip"+i,i);
	dateClip.createTextField("day"+i,i,0,0,30,30);
	
	dateClip["day"+i].border = true;
	dateClip["day"+i].text = i;
	dateClip._x = columnWidth * i;
	
	firstDay++;
	
	if(firstDay == 7){
		// start a new row
		firstDay = 0;
	}
}

```

how do i go about creating a new row in that ‘if’ statement? i don’t want to hardcode any values in there.

thanks. fumeng.

---

<div class="post-metadata">

### Author: ![cycom](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@cycom](https://forum.kirupa.com/u/cycom)
#### Post date: [August 10, 2004, 2:31pm UTC](https://forum.kirupa.com/t/creating-a-grid/118954/2 "2004-08-10T14:31:49Z")

</div>

try this…

[AS]  
numColumns = 7;  
columnWidth = Stage.width/7;  
rowHeight = Stage.height/6;  
firstDay = 1;  
lastDay = 30;  
currentDay = firstDay;  
currentRow = 0;

for(i=1; i\<=lastDay; i++){  
var dateClip = \_root.createEmptyMovieClip(“dateClip”+i,i);  
dateClip.createTextField(“day”+i,i,0,0,30,30);

dateClip[“day”+i].border = true;  
dateClip[“day”+i].text = i;  
dateClip.\_x = columnWidth \* currentDay;  
dateClip.\_y = rowHeight \* currentRow;

currentDay++;

if(currentDay == numColumns){  
// start a new row  
currentDay = 0;  
currentRow++;  
}  
}  
[/AS]

---

<div class="post-metadata">

### Author: ![fumeng](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@fumeng](https://forum.kirupa.com/u/fumeng)
#### Post date: [August 10, 2004, 7:46pm UTC](https://forum.kirupa.com/t/creating-a-grid/118954/3 "2004-08-10T19:46:05Z")

</div>

wow. that works! thank you so much. you don’t know how long i’ve been struggling with this.

there is only one thing. there are two rows above this and i need this row to start as the 3rd row. check out the image to see what is happening. how can i do this without actually hardcoding a value (this will be a component so can’t use hardcoded values – users will be able to resize this).

thank you very much for your help. fumeng.

---

<div class="post-metadata">

### Author: ![cycom](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@cycom](https://forum.kirupa.com/u/cycom)
#### Post date: [August 10, 2004, 8:58pm UTC](https://forum.kirupa.com/t/creating-a-grid/118954/4 "2004-08-10T20:58:01Z")

</div>

that’s simple, just add an offset to currentRow

[AS]  
dateClip.\_y = rowHeight \* (currentRow+2);  
[/AS]

or alternatively

[AS]  
dateClip.\_y = rowHeight \* currentRow + offsetY;  
[/AS]

if offsetY is not a multiple of rowHeight.

---

<div class="post-metadata">

### Author: ![fumeng](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@fumeng](https://forum.kirupa.com/u/fumeng)
#### Post date: [August 11, 2004, 5:51pm UTC](https://forum.kirupa.com/t/creating-a-grid/118954/5 "2004-08-11T17:51:21Z")

</div>

hey. thank you very much cycom! it worked absolutely perfect!

thanks. fumeng.
