Copy link to clipboard
Copied
Hi,
I was wondering if there is a way to make a menu of buttons from an array arrange themselves in a 3x3 grid.
I have used code i have gotten from this forum to place them next to each other onto the stage (which was quit awesome) and i have found code to place them in a rotating cell from an array but is it possible to do it as a grid?
Any help would be great
Copy link to clipboard
Copied
use Math.floor and the modulo operator to construct grids:
var xSpace:int = 100;
var ySpace:int=100;
var rowNum:int=3;
var colNum:int=3;
for(var i:int=0;i<yourarray.length;i++){
yourarray.x=xSpace*i%rowNum;
yourarray.y=ySpace*Math.floor(i/colNum);
}
Copy link to clipboard
Copied
Thanks kglad,
It work but it doesn't set the second and third row under the first row instead it places the second row's x position at the end of the first row.
Have I done something wrong?
Copy link to clipboard
Copied
use:
yourarray.x=xSpace*(i%rowNum);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now