DistributionCollection

Kind of class:class
Inherits from:CoreObject
Version:05/09/07
Author:Aaron Clinger
Classpath:org.casaframework.layout.DistributionCollection
File last modified:Sunday, 19 August 2007, 13:43:33
Creates the mechanism to distribute MovieClips, TextFields and Buttons to a vertical or horzontal grid of columns and rows.
Example:
var distribution:DistributionCollection = new DistributionCollection();
this.distribution.setRectangle(new Rectangle(10, 10, 400, Number.POSITIVE_INFINITY));
this.distribution.setMargin(0, 5, 5, 0);

var len:Number = 5;
while (len--) {
    this.distribution.addItem(this.attachMovie("box", "box" + len + "_mc", this.getNextHighestDepth()));
}

this.distribution.positionItems();

Constructor

DistributionCollection

function DistributionCollection (snapToPixel:Boolean)
Creates a new DistributionCollection instance.
Parameters:
snapToPixel:
[optional] Force the position of all items to whole pixels true, or to let items be positioned on sub-pixels false; defaults to false.

Instance methods

addItem

function addItem (item:Object, position:Number) : Boolean
Adds or reorders item to receive distribution position updates.
Parameters:
item :
A MovieClip, TextField or Button.
position:
[optional] An integer that specifies the index of the where the item will be inserted into the distribution; defaults to the end of the distribution.
Returns:
Returns true if item was of type MovieClip, TextField or Button and was successfully added; otherwise false.

destroy

function destroy () : Void

findItemPosition

function findItemPosition (item:Object) : Number

getBoundingRectangle

function getBoundingRectangle () : Rectangle
Returns:
Returns the actual area and position the items in the distribution occupy.

getItemAt

function getItemAt (position:Number) : Object

getRectangle

function getRectangle () : Rectangle
Returns:
Returns the area and position of the distribution that was defined with setRectangle.

positionItems

function positionItems () : Void
Applies the distribution layout for all items added with addItem.
Usage note:
positionItems is automatically called after setRectangle and setMargin.

removeItem

function removeItem (item:Object) : Boolean
Removes item previously added with addItem from receiving distribution updates. Leaves item at its current position.
Parameters:
item:
A MovieClip, TextField or Button you wish to remove.
Returns:
Returns true if item was successfully found and removed; otherwise false.

setMargin

function setMargin (marginTop:Number, marginRight:Number, marginBottom:Number, marginLeft:Number) : Void
Defines the spacing between items in the distribution.
Parameters:
marginTop :
Sets the top spacing of an element.
marginRight :
Sets the right spacing of an element.
marginBottom:
Sets the bottom spacing of an element.
marginLeft :
Sets the left spacing of an element.

setRectangle

function setRectangle (rectangle:Rectangle) : Boolean
Defines the area and position of the distribution.
Parameters:
rectangle:
A rectangle defining either the max width or height boundries of the distribution
Returns:
Returns true if the rectangle was valid and applied; otherwise false.
Usage note:
Either the rectangle's width or height must defined as Number.POSITIVE_INFINITY.