GridBuilder
| Kind of class: | public class |
|---|---|
| Package: | com.trycatch.utils |
| Inherits from: | Object |
| Version: | 1.2 |
| Author: | JP DeVries, Nemo Design |
| Classpath: | com.trycatch.utils.GridBuilder |
| File last modified: | Thursday, 14 May 2009, 17:53:33 |
The
Instantiate a new
Below is an example swf of what the above code generates.
GridBuilder is a display utility that a group of display objects of the same width and height, and lays them out in a grid format.Instantiate a new
GridBuilder, call the createGrid method, and add the returned Sprite to whatever DisplayList you wish.public function GridBuilderExample() { // create an Array to hold some squares var _squares:Array = new Array(); // create the squares for (var i:int = 0; i < 10; i++) { var _square:Sprite = _createSquare(); _squares.push(_square); } // create a GridBuilder instance var _gridBuilder:GridBuilder = new GridBuilder("square-grid"); // create the grid var _grid:Sprite = _gridBuilder.createGrid(_squares, 254, 50, 50, 1, 1); // add the grid to the display list addChild(_grid); // no longer needed, handles garbage collection _gridBuilder.destroy(); } // creates a 50px square private function _createSquare() : Sprite { var _square:Sprite = new Sprite(); _square.graphics.beginFill(0xd7d7cf, 1); _square.graphics.drawRect(0, 0, 50, 50); return _square; }
Below is an example swf of what the above code generates.
See also:
Summary
Constructor
- GridBuilder (_id:String = "default-grid")
- When instantiating a new GridBuilder instance, passing in a unique id will allow you fetch that instance later from a static getInstance method.
Instance properties
- gridWidth : Number
- The width of the grid.
- gridItems : Array
- An Array of individual DisplayObjects to be laid out as a grid.
- gridItemWidth : Number
- The width of the individual grid items.
- gridItemHeight : Number
- The height of the individual grid items.
- gutterHorizontal : Number
- The amount of horizontal space between each grid item.
- gutterVertical : Number
- The amount of vertical space between each grid item.
- grid : Sprite
- The grid created by createGrid.
- colCount : Number
- The number of columns built.
- rowCount : Number
- The number of rows built.
- numGridItems : int
- The number of grid items built.
- gridPoints : Array
- An Array that holds Point objects.
Class methods
- getInstance (_id:String) : GridBuilder
- Returns the requested GridBuilder instance.
- destroyAll : void
- Invokes destroy method on all GridBuilder instances.
Instance methods
- createGrid (__gridItems:Array, __gridWidth:Number, __gridItemWidth:Number, __gridItemHeight:Number, __gutterHorizontal:Number = 1, __gutterVertical:Number = 1) : Sprite
- Takes an Array of DisplayObjects, each to be used as an individual grid item, along with width, height, and gutter properites.
- destroy : void
- Destroys gridItems, gridPoints, and grid properties.
Constructor
GridBuilder
public function GridBuilder (
_id:String = "default-grid")
When instantiating a new
GridBuilder instance, passing in a unique id will allow you fetch that instance later from a static getInstance method. Instance properties
colCount
public colCount:Number
(read)
The number of columns built.
gridItemHeight
public gridItemHeight:Number
(read)
The height of the individual grid items. All grid items must have the same height.
gridItems
public gridItems:Array
(read)
An
Array of individual DisplayObjects to be laid out as a grid. gridItemWidth
public gridItemWidth:Number
(read)
The width of the individual grid items. All grid items must have the same width.
gridPoints
public gridPoints:Array
(read)
An
Array that holds Point objects. Each Point represents the x,y coordinates of its associative grid item. gridWidth
public gridWidth:Number
(read)
The width of the grid. The height of the grid is calculated automatically. Your
gridWidth should follow this algorithm.gridWidth = (colCount * gridItemWidth) + ((colCount-1) * gutterVertical) gutterHorizontal
public gutterHorizontal:Number
(read)
The amount of horizontal space between each grid item.
gutterVertical
public gutterVertical:Number
(read)
The amount of vertical space between each grid item.
numGridItems
public numGridItems:int
(read)
The number of grid items built. This is the length of gridItems.
rowCount
public rowCount:Number
(read)
The number of rows built.
Class methods
destroyAll
public static function destroyAll (
) : void
Invokes destroy method on all GridBuilder instances.
See also:
getInstance
Returns the requested GridBuilder instance.
Parameters:
_id:
The id of the requested instance.
Instance methods
createGrid
public function createGrid (
__gridItems:Array,
__gridWidth:Number,
__gridItemWidth:Number,
__gridItemHeight:Number,
__gutterHorizontal:Number = 1,
__gutterVertical:Number = 1) : Sprite
Takes an
Array of DisplayObjects, each to be used as an individual grid item, along with width, height, and gutter properites. Parameters:
_gridItems :
An
Array of DisplayObjects to be laid out in a grid format._gridWidth :
The width of the grid.
_gridItemWidth :
The width of the individual grid item.
_gridItemHeight :
The height of the individual grid item.
_gutterHorizontal:
The amount of horizontal space between each grid item.
_gutterVertical :
The amount of vertical space between each grid item.
See also:
destroy
public function destroy (
) : void
Destroys gridItems, gridPoints, and grid properties. This method handles garbage collection for this class.
See also: