GridMaker

Package:
Class:
Inheritance:
biz.flashscript.displayobjects
public class GridMaker
N/A
The GridMaker class allows to create grids. Use the constructor new GridMaker().
Public Methods
Method Defined By
GridMaker()
Creates a new instance of the GridMaker class.
GridMaker
makeGrid(_target:Object, nameClass:String, nameClip:Object, _lastRow:int, _lastCell:int, _addFunction:Function=null, _xDistance:int=0, _yDistance:int=0, _xAddition:int=0, _yAddition:int=0)
Initiates creating the grid.
GridMaker
arrangeGrid(myArray:Array, _lastRow:int, _lastCell:int, _addFunction:Function=null, _xDistance:int=0, _yDistance:int=0, _xAddition:int=0, _yAddition:int=0)
Will create a grid from existing objects, which are collected in an array.
GridMaker
Constructor Detail
GridMaker ()  Constructor
public function GridMaker()
Intializes a new GridMaker instance.
Method Detail

makeGrid()  method
public function makeGrid(_target:Object, nameClass:String, nameClip:Object, _lastRow:int, _lastCell:int, _addFunction:Function=null, _xDistance:int=0, _yDistance:int=0, _xAddition:int=0, _yAddition:int=0):void

This method will initiate creating the grid.

Parameters

  • _target:Object ____ Specifies the object where to create the grid.
  • nameClass:String ____ The name of the object from the library.
  • nameClip:Object ____ The identifier for the new grid objects,
  • _lastRow:int ____ The vertical row.
  • _lastCell:int ____ The horizontal row.
  • _addFunction:Function=null ____ Optional: a function for each grid object, default is null,
  • _xDistance:int=0 ____ Optional: the distance between horizontal objects, default is 0,
  • _xDistance:int=0 ____ Optional: the distance between horizontal objects, default is 0,
  • _yDistance:int=0 ____ Optional: the distance between vertical objects, default is 0,
  • _xAddition:int=0 ____ Optional: the x distance of the grid, default is 0,
  • _yAddition:int=0 ____ Optional: the y distance of the grid, default is 0.

arrangeGrid()  method
public function arrangeGrid(myArray:Array, _lastRow:int, _lastCell:int, _addFunction:Function=null, _xDistance:int=0, _yDistance:int=0, _xAddition:int=0, _yAddition:int=0):void

Will create a grid from existing objects, which are collected in an array.

Parameters

  • myArray:Array ____ The array, which has the identifiers of all the objects to create a grid from.
  • _lastRow:int ____ The vertical row.
  • _lastCell:int ____ The horizontal row.
  • _addFunction:Function=null ____ Optional: a function for each grid object, default is null,
  • _xDistance:int=0 ____ Optional: the distance between horizontal objects, default is 0,
  • _xDistance:int=0 ____ Optional: the distance between horizontal objects, default is 0,
  • _yDistance:int=0 ____ Optional: the distance between vertical objects, default is 0,
  • _xAddition:int=0 ____ Optional: the x distance of the grid, default is 0,
  • _yAddition:int=0 ____ Optional: the y distance of the grid, default is 0.
Examples
Create a new fla file and name it GridMaker.fla. Place the fla in the same folder as the biz folder. Create two MovieClips one with the identifier Circle and the other with the identifier Square. Export to actionscript. Place a dynamic textbox at the bottom of the movie and give the id myText. Then create an Actionscript file, name it Gridmaker.as and place this script.
package 
{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import biz.flashscript.displayobjects.GridMaker;
	import flash.events.Event;
	import flash.text.TextField;

	public class Gridmaker extends Sprite
	{
		public var myText:TextField;
		public function Gridmaker ():void
		{
			var cm:GridMaker=new GridMaker();
			var mc:MovieClip;
			/*
			* Creating squares, adding a function to it allows
			* further manipulation of the Grid. Here the function
			* is to remove a square on mouse click.
			*/
			var _target:Object = this;
			var _className = "Square";
			var _nameClip:MovieClip = mc;
			var lastRow:int = 5;
			var lastCell:int = 4;
			var xD:int = 55;
			var yD:int = 55;
			var xAdd:int = 10;
			var yAdd:int = 10;
			var functionname:Function = mcFunction;
			addChild(cm);
			cm.addEventListener ("gridReady", gridHandler);
			cm.makeGrid (_className,5,4,functionname,xD,yD,xAdd,yAdd);
			/*
			* Creating circles. This function simply arranges a custom grid.
			*/
			var _mc:Circle;
			var myArray:Array=new Array();
			for (var i=0; i<=20; i++)
			{
				mc=new Circle();
				myArray.push (mc);
				addChild (mc);
			}
			cm.arrangeGrid (myArray,5,5,250,10);
		}
		private function mcFunction (mc):void
		{
			myText.appendText(mc.id + "  ");
			myText.appendText(mc.name + "\n");
			mc.parent.removeChild (mc);
		}
		private function gridHandler (event:Event):void
		{
			trace ("SUCCESS");
		}
	}
}