10-16-2008
Actionscript 3: Dynamic Rows and Columns
Sometimes you want to create rows and columns dynamically, and for a long time I didn’t know how, with some research and some documentation perusal, I found that using the % modulo will help you create rows and columns:
var numOfColumns:int = 5;
var spacer:int = 10;
for(var i:int; i < 10; i++)
{
var item:ItemToAdd = new ItemToAdd();
item.x = (i % numOfColumns) * (item.width + spacer);
item.y = Math.floor(i / numOfColumns) * (item.height + spacer);
addChild(item);
}