Skip to main content
Known Participant
April 8, 2013
Question

make a grid menu using an array

  • April 8, 2013
  • 1 reply
  • 454 views

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

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 8, 2013

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);

}

jake0037Author
Known Participant
April 8, 2013

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?

kglad
Community Expert
Community Expert
April 8, 2013

use:

yourarray.x=xSpace*(i%rowNum);