class com.senocular.display

Layout

Extends: LayoutConstraint

Class Information

Author
Trevor McCauley, www.senocular.com
Version
1.0.0
Description
The Layout class is used to create dynamically sized and positioned layouts that adjust content to fit within a containing boundary. Layout instances are (usually) associated with single target DisplayObject instances and dispatch a CHANGE event when it's layout has changed allowing that target to fit itself to the layout's rectangle boundary (rect).

Using the LayoutManager class, Layout instances can be automatically updated when they are modified and propagate their changes to child display objects or layouts that are also using the same LayoutManager when contained within the same display hierarchy. Without the using LayoutManager, updates can be forced using the draw() method and can be propagated through child layouts if a hierarchy has been defined by setting the parent property for layouts.

If LayoutManager is not being used, you would need to update your layout using the draw() method (this is sometimes still needed when the LayoutManager class is being used). This method dispatches the CHANGE event for the layout and all of its children also affected by the change in the layout if there was a change. It is generally the responsibility of the target instance to physically position and size itself to a layout's rect during the CHANGE event in an event handler, though the Layout class does provide an automatic handler that will fit a target to the layout's rect when useDefaultChangeHandler is true. When the stage is used as a target for a layout, that layout will automatically update during the stage's RESIZE event and fit itself to match the size of the stage.

Each layout instance is also an instance of a LayoutConstraint. The LayoutConstraint class defines the constraints specific to each layout that affect the direct contents of the target display object associated with that layout. Child display objects of that target can have layouts which will be contained within the target's layout. An optional children property can be set to a Layout or LayoutConstraint instance to define a sublayout for constraining child layouts.
Constructors
Layout() Constructor for creating new Layout instances. If you want your instances to automatically update, you would generally favor LayoutManager.registerNewLayout() in favor of creating layout instances with the Layout constructor.
Properties
useDefaultChangeHandler The change handler for updating a display object when its layout has changed. This relates to the changeHandler passed into the Layout constructor and is optional to using addEventListener with the layout's Event.CHANGE event yourself.
parent The parent layout in which the current layout is contained. This property will return the parent layout if that parent had this layout added to it using addChild(), otherwise if the layout within the parent of the layout's target display object has been registered to the same LayoutManager instance, it will return that layout. If neither are the case, null is returned [read-only].
children An optional constraint used for layouts contained withinthe current layout. By default, layouts within other layouts fit to the extends of the containing layout. By defining a children layout constraint layouts that are children of the current layout can be contained to a separate set of boundaries. The children property is null by default. To use the children layout, you must first assign it to a Layout or LayoutConstraint instance.
manager The LayoutManager instance managing this layout [read-only].
target The target display object this layout affects [read-only].
Methods
defaultChangeHandler() A predefined change handler for generic objects being fit within a contraint's bounds. This handler maps the display objects x, y, width and height properties directly to the respective properties within the layout rect.
clone() Creates a new copy of the current Layout instance. Cloned layouts do do not retain an association with any LayoutManager used with the original.
addChild() Adds a layout to be the child of the current layout. As a child, changes from this layout will be propagated to that layout to assure that it is properly constrained within this layout's boundaries.
removeChild() Removes a layout as a child of this layout.
draw() Updates the layout (current and children) dimensions dispatching the Layout.CHANGE event for this layout or any child layouts affected.

Constructors

Layout()

public function Layout(target:DisplayObject = null, useDefaultChangeHandler:Boolean = false)
Constructor for creating new Layout instances. If you want your instances to automatically update, you would generally favor LayoutManager.registerNewLayout() in favor of creating layout instances with the Layout constructor.
Parameters:
targetThe target display object this layout instance will be associated. Of the target is stage, an automatic listner for the RESIZE event will be added to update the layout's size to match the stage's [optional].
changeHandlerA change handler function that will automatically be set to listen to the CHANGE event for the new layout instance [optional].

Properties

useDefaultChangeHandler

public function get useDefaultChangeHandler():Boolean
public function set useDefaultChangeHandler(value:Boolean):void
The change handler for updating a display object when its layout has changed. This relates to the changeHandler passed into the Layout constructor and is optional to using addEventListener with the layout's Event.CHANGE event yourself.

parent

public function get parent():Layout
The parent layout in which the current layout is contained. This property will return the parent layout if that parent had this layout added to it using addChild(), otherwise if the layout within the parent of the layout's target display object has been registered to the same LayoutManager instance, it will return that layout. If neither are the case, null is returned [read-only].

children

public function get children():LayoutConstraint
public function set children(value:LayoutConstraint):void
An optional constraint used for layouts contained withinthe current layout. By default, layouts within other layouts fit to the extends of the containing layout. By defining a children layout constraint layouts that are children of the current layout can be contained to a separate set of boundaries. The children property is null by default. To use the children layout, you must first assign it to a Layout or LayoutConstraint instance.

manager

public function get manager():LayoutManager
The LayoutManager instance managing this layout [read-only].

target

public function get target():DisplayObject
public function set target(value:DisplayObject):void
The target display object this layout affects [read-only].

Methods

defaultChangeHandler()

public static function defaultChangeHandler(event:Event):void
A predefined change handler for generic objects being fit within a contraint's bounds. This handler maps the display objects x, y, width and height properties directly to the respective properties within the layout rect.
Parameters:
eventThe CHANGE event object dispatched to this handler when a layout has changed.

clone()

override public function clone():LayoutConstraint
Creates a new copy of the current Layout instance. Cloned layouts do do not retain an association with any LayoutManager used with the original.

addChild()

public function addChild(childLayout:Layout):Layout
Adds a layout to be the child of the current layout. As a child, changes from this layout will be propagated to that layout to assure that it is properly constrained within this layout's boundaries.
Parameters:
childLayoutThe layout to be made a child of the current layout.

removeChild()

public function removeChild(childLayout:Layout):Layout
Removes a layout as a child of this layout.
Parameters:
childLayoutThe layout to be removed as a child of the current layout.

draw()

public function draw():void
Updates the layout (current and children) dimensions dispatching the Layout.CHANGE event for this layout or any child layouts affected.

Page generated: 11:09 pm on July 31, 2007