Generate a Grid in AS3


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.