Posted By

sidneydekoning on 05/14/09


Tagged


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

StrawMan
sidneydekoning
flashinit
johnwun
Pingpongbal
TrentSkunk
alptugan
davidino1978
tspitzr
adrianparr
elkraneo


Generate a Grid in AS3


 / Published in: ActionScript 3
 

  1. // Generate a grid when giving in columns and rows
  2.  
  3. function generateGrid( object:Sprite, rows:Number, column:Number, w:Number, h:Number ):void {
  4. var totalWidth:Number = column * w;
  5. var totalHeight:Number = rows * h;
  6.  
  7. // Do for loop for columns
  8. for(var i:Number = 0; i <= column ; i++) {
  9. object.graphics.moveTo( w * i, 0 );
  10. object.graphics.lineTo( w * i, totalHeight );
  11. }
  12. // Do for loop for rows
  13. for(var j:Number = 0; j <= rows ; j++) {
  14. object.graphics.moveTo( 0, h * j );
  15. object.graphics.lineTo( totalWidth, h * j );
  16. }
  17. // Now we have a grid
  18. }
  19.  
  20. var s:Sprite = new Sprite();
  21. s.graphics.lineStyle(1, 0x000000);
  22. addChild(s)
  23.  
  24. generateGrid(s, 3, 3, 100, 100);

Report this snippet  

You need to login to post a comment.