DistributionCollection

Kind of class:class
Inherits from:EventDispatcher < CoreObject
Version:12/01/08
Author:Aaron Clinger, Jon Adams
Classpath:org.casalib.layout.DistributionCollection
File last modified:Monday, 01 December 2008, 13:35:13
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();
Events broadcasted to listeners:
  • onPosition = function (sender:DistributionCollection) {}

Summary


Constructor
Class properties
Instance methods
  • setRectangle (rectangle:Rectangle) : Boolean
    • Defines the area and position of the distribution.
  • getRectangle : Rectangle
  • getBoundingRectangle : Rectangle
  • setMargin (marginTop:Number, marginRight:Number, marginBottom:Number, marginLeft:Number) : Void
    • Defines the spacing between items in the distribution.
  • addItem (item:Object, position:Number) : Boolean
    • Adds or reorders item to receive distribution position updates.
  • removeItem (item:Object) : Boolean
    • Removes item previously added with addItem from receiving distribution updates.
  • getItemAt (position:Number) : Object
    • Returns the element at the specified position in the collection.
  • findItemPosition (item:Object) : Number
    • Finds the position of the first occurrence of a specified item.
  • getItems : Array
    • Returns an Array containing all of the elements in the collection in order.
  • positionItems : Void
    • Applies the distribution layout for all items added with addItem.
  • destroy : Void

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.

Class properties

EVENT_POSITION

static EVENT_POSITION:String = 'onPosition'
(read,write)

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

Finds the position of the first occurrence of a specified item.
Parameters:
item:
The element to search for.

getBoundingRectangle

function getBoundingRectangle (

Returns:
  • Returns the actual area and position the items in the distribution occupy.

getItemAt

function getItemAt (
position:Number) : Object

Returns the element at the specified position in the collection.
Parameters:
position:
The position of the element to return.
Returns:
  • The element at the specified position in the collection.

getItems

function getItems (
) : Array

Returns an Array containing all of the elements in the collection in order.
Returns:
  • Returns an Array containing all of the elements in the collection in order.

getRectangle

function getRectangle (

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.
Events broadcasted to listeners:
  • onPosition = function (sender:DistributionCollection) {}
Usage note:

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.