Return to Snippet

Revision: 13963
at June 4, 2009 04:08 by sidneydekoning


Updated Code
// Generate a grid when giving in columns and rows

function generateGrid( object:Sprite, rows:Number, column:Number, w:Number, h:Number ):void {						
	var totalWidth:Number = column * w;
	var totalHeight:Number = rows * h;
	
	// Do for loop for columns		
	for(var i:Number = 0; i <= column ; i++) {
		object.graphics.moveTo( w * i, 0 );
		object.graphics.lineTo( w * i, totalHeight );	
	}
	// Do for loop for rows
	for(var j:Number = 0; j <= rows ; j++) {
		object.graphics.moveTo( 0, h * j );
		object.graphics.lineTo( totalWidth, h * j );	
	}
	// Now we have a grid
}

var s:Sprite = new Sprite();
s.graphics.lineStyle(1, 0x000000);
addChild(s)

generateGrid(s, 3, 3, 100, 100);

Revision: 13962
at May 14, 2009 10:05 by sidneydekoning


Initial Code
// Generate a grid when giving in comulns and rows

public static function generateGrid( object:Sprite, rows:Number, column:Number, w:Number, h:Number ):void {						
	var totalWidth:Number = column * w;
	var totalHeight:Number = rows * h;
	
	// Do for loop for columns		
	for(var i:Number = 0; i <= column ; i++) {
		object.graphics.moveTo( w * i, 0 );
		object.graphics.lineTo( w * i, totalHeight );	
	}
	// Do for loop for rows
	for(var j:Number = 0; j <= rows ; j++) {
		object.graphics.moveTo( 0, h * j );
		object.graphics.lineTo( totalWidth, h * j );	
	}
	// Now we have a grid
}

Initial URL

                                

Initial Description

                                

Initial Title
Generate a Grid in AS3

Initial Tags

                                

Initial Language
ActionScript 3