Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

make a grid menu using an array

New Here ,
Apr 08, 2013 Apr 08, 2013

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

TOPICS
ActionScript
432
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2013 Apr 08, 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2013 Apr 08, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2013 Apr 08, 2013
LATEST

use:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines