Simple grid?

Hi fellow Kuripians :),

Im having trouble creating a grid dynamically with AS. Ive used the nested for loop method as in Kirupa’s example http://www.kirupa.com/developer/actionscript/grid.htm , so I know how to create grids with hard coded box numbers, i.e. 10 boxes across (x) and 10 down (y)…

What im trying to achieve is a grid which is limited to 4 boxes across and n boxes down depending on the total number of boxes that need to be created. Make sense ? lol

Im stuck, and it seems so simple?