fumeng
August 10, 2004, 2:09pm
1
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:
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.
cycom
August 10, 2004, 2:31pm
2
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]
fumeng
August 10, 2004, 7:46pm
3
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.
cycom
August 10, 2004, 8:58pm
4
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.
fumeng
August 11, 2004, 5:51pm
5
hey. thank you very much cycom! it worked absolutely perfect!
thanks. fumeng.