Posted By

taboularasa on 07/17/08


Tagged

textmate function as3 grid buttons actionscript3


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

THEPWN3R
abbey
alptugan
tspitzr


AS3: Create a grid of bottons


 / Published in: ActionScript 3
 

  1. private function generateBoard(startX:Number,startY:Number,totalRows:Number,totalCols:Number,buttonSize:Number):void {
  2. buttons = new Array();
  3. var colCounter:uint;
  4. var rowCounter:uint;
  5. for(rowCounter = 0; rowCounter < totalRows; rowCounter++) {
  6. for(colCounter = 0; colCounter < totalCols; colCounter++) {
  7. var b:Button = new Button();
  8. b.x = startX + (colCounter*buttonSize);
  9. b.y = startY + (rowCounter*buttonSize);
  10. b.addEventListener(MouseEvent.CLICK, letterClicked);
  11. b.label = getRandomLetter().toUpperCase();
  12. b.setSize(buttonSize,buttonSize);
  13. b.name = "buttonRow"+rowCounter+"Col"+colCounter;
  14. addChild(b);
  15.  
  16. buttons.push(b);
  17. }
  18. }
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: nuthman on March 3, 2010

Nice! I have written a nice little class that builds a grid out of supplied display objects or class of your choice.. I have also explained the code so that you can get a foundation of how to start creating grids for building puzzle type games. Check it out: http://www.as3blog.org/?p=50

Posted By: vel on September 13, 2010

Code snippet - AS3: Create a grid of bottons on Snipplr

Posted By: vel on September 13, 2010

1. private function generateBoard(startX:Number,startY:Number,totalRows:Number,totalCols:Number,buttonSize:Number):void { 2. buttons = new Array(); 3. var colCounter:uint; 4. var rowCounter:uint; 5. for(rowCounter = 0; rowCounter < totalRows; rowCounter++) { 6. for(colCounter = 0; colCounter < totalCols; colCounter++) { 7. var b:Button = new Button(); 8. b.x = startX + (colCounterbuttonSize); 9. b.y = startY + (rowCounterbuttonSize); 10. b.addEventListener(MouseEvent.CLICK, letterClicked); 11. b.label = getRandomLetter().toUpperCase(); 12. b.setSize(buttonSize,buttonSize); 13. b.name = "buttonRow"+rowCounter+"Col"+colCounter; 14. addChild(b); 15.

16. buttons.push(b); 17. } 18. } 19. }

You need to login to post a comment.