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);
}
This works perfect.. Thank you very much
this is sweet, thanks dude, this helped me with a thumbnail gallery i am building
What a life saver with just 10 lines of code of amazing.
AMAZING!
Gracias from BA!
Almost a year later, and this little piece of script is the gift that keeps on giving. THANK YOU! Exactly what I needed.
I use this everyday, so thank you!
you are the man!!!!!!
OH MY GOSH!!!! Thank you!
Thank you so much!