Packagecom.soundstep.ui.layouts
Classpublic class CanvasUI
InheritanceCanvasUI Inheritance flash.display.MovieClip
SubclassesHBoxUI, TileUI, VBoxUI

Author: Romuald Quantin - www.soundstep.com
Class version: 3.0.1
Actionscript version: 3.0
Copyright: Mozilla Public License 1.1 (MPL 1.1)
http://www.opensource.org/licenses/mozilla1.1.php
You can use BaseUI in any flash site, except to include/distribute it in another framework, application, template, component or structure that is meant to build, scaffold or generate source files.

Date: 08-2008
Usage:
A CanvasUI layout container defines a rectangular region in which you place children DisplayObject. It is the only container that lets you explicitly specify the location of its children.
CanvasUI is a subclass of MovieClip, you have the choice to use addChild or addChildUI, this last method will automaticaly create an ElementUI instance and make you able to use properties like top, bottom, left, right and all other properties of the Element class.
Not only for the children, you can use the Element properties on the canvas itself, the difference with the ElementUI properties is that you have specific properties for the percentage size: percentWidth and percentHeight.
Methods to manage the ElementUI instances have been added, like for example getChildUI or removeChildUI.
The CanvasUI constructor takes 4 optionals parameters: width, height, layoutScroll and layout mask.
By default, CanvasUI build a mask to show only the content within the size specified and creates scrollbars (scrollpane instance) if the content is bigger than the size specified.


Example
  // create layout
  var canvas:CanvasUI = new CanvasUI();
  addChild(canvas);
  canvas.canvasAlpha = .2;
  // add children
  var s:Sprite = new Sprite();
  s.name = "mySprite";
  s.graphics.beginFill(0x0000FF, .5);
  s.graphics.drawRect(0, 0, 150, 300);
  canvas.addChildUI(s);
  canvas.getChildUIByName("mySprite").right = 20;
  canvas.getChildUI(s).bottom = 20;
  var txt:TextField = new TextField();
  txt.name = "myTextField";
  txt.autoSize = TextFieldAutoSize.LEFT;
  txt.text = "TextField test";
  canvas.addChildUI(txt);
  canvas.getChildUIByName("myTextField").horizontalCenter = 0;
  canvas.getChildUI(txt).verticalCenter = 0;
  // change canvas ui property 
  canvas.ratio = ElementUI.RATIO_IN;
  canvas.properties = {top:10, bottom:10, left:10, right:10};
  



Public Properties
 PropertyDefined by
  alignX : String
horizontal alignment when the property ratio is set to ElementUI.RATIO_IN or ElementUI.RATIO_OUT
can accept ElementUI.ALIGN_LEFT, ElementUI.ALIGN_RIGHT, ElementUI.ALIGN_CENTER
CanvasUI
  alignY : String
vertical alignment when the property ratio is set to ElementUI.RATIO_IN or ElementUI.RATIO_OUT
can accept ElementUI.ALIGN_CENTER, ElementUI.ALIGN_TOP, ElementUI.ALIGN_BOTTOM
CanvasUI
  baseUI : BaseUI
[read-only] get the instance of the BaseUI class, used for the children added with addChild or addChildUI
CanvasUI
  bottom : Number
bottom value (from the reference), Number or String
CanvasUI
  buttonMode : Boolean
Specifies the button mode of this sprite
CanvasUI
  bypassSize : Boolean
whether or not the DisplayObject will be resized (not working with ratio set to RATIO_IN or RATIO_OUT)
CanvasUI
  canvasAlpha : Number
background alpha of the canvas
CanvasUI
  canvasColor : uint
background color of the canvas
CanvasUI
  container : Sprite
[read-only] get the instance of the container, it contains the children added with addChild and addChildUI
CanvasUI
  forceReferenceHeight : Number
force the height of the reference
CanvasUI
  forceReferenceWidth : Number
force the width of the reference
CanvasUI
  height : Number
height of the canvas
CanvasUI
  horizontalCenter : Number
horizontal center value (from the reference), Number or String
CanvasUI
  initialWidth : Number
width of the DisplayObject when added to the BaseUI instance
CanvasUI
  keepOnScreen : Boolean
keep a DisplayObject in the screen
CanvasUI
  layoutMask : Mask
[read-only] get the instance of the mask
CanvasUI
  left : Number
left value (from the reference), Number or String
CanvasUI
  mouseChildren : Boolean
Determines whether or not the children of the object are mouse enabled
CanvasUI
  numChildren : int
[read-only] Returns the number of children of the CanvasUI container
CanvasUI
  onStage : Boolean
set the stage as a reference to calculate position ans sizes, if false the parent will be the reference
CanvasUI
  percentHeight : *
[write-only] set the height percentage (will accept Number or String, with or without the percentage character
CanvasUI
  percentWidth : *
[write-only] set the width percentage (will accept Number or String, with or without the percentage character
CanvasUI
  properties : Object
Object to get or set the CanvasUI properties, for example:
element.properties = {top:0, bottom:"20", onStage:false, width:"50%"};
CanvasUI
  ratio : String
type of ratio of the CanvasUI, can be ElementUI.RATIO_IN or ElementUI.RATIO_OUT
any other String will set the ratio to none
the following properties cannot be set or are not used a ratio has been specified:
x, y, width, height, horizontalCenter and verticalCenter
CanvasUI
  reference : DisplayObjectContainer
specify a DisplayObjectContainer reference on which the size and position of the ElementUI will refer to
if not set, the onStage property value is the reference (onStage true = stage, onStage false = parent)
CanvasUI
  right : Number
right value (from the reference), Number or String
CanvasUI
  scrollPane : *
[read-only] get the instance of the scrollpane used for the scrollbars
you must cast the return: Scrollpane(canvas.scrollpane), the wild card has been used not to import the SCrollpane classes if not used
CanvasUI
  top : Number
top value (from the reference), Number or String
CanvasUI
  ui : ElementUI
[read-only] get a the wrapper ElementUI instance
CanvasUI
  useInitialSize : Boolean
use the size that has been recorded when the DisplayObject has been added to the BaseUI instance
useful when a mask or other DisplayObject can disturb the real size of the DisplayObject
CanvasUI
  verticalCenter : Number
vertical center value (from the reference), Number or String
CanvasUI
  width : Number
width of the canvas
CanvasUI
  wrapper : Wrapper
[read-only] get the instance of the wrapper
CanvasUI
  x : Number
x position of the canvas, Number or String
CanvasUI
  y : Number
y position of the canvas
CanvasUI
Public Methods
 MethodDefined by
  
CanvasUI(widthLayout:Number = 100, heightLayout:Number = 100, layoutScrollbar:Boolean = true, layoutMask:Boolean = true)
Constructor Create an instance of the CanvasUI class
CanvasUI
  
addChild(child:DisplayObject):DisplayObject
Adds a child DisplayObject instance to this CanvasUI container
CanvasUI
  
addChildAt(child:DisplayObject, index:int):DisplayObject
Adds a child DisplayObject instance to the CanvasUI container
CanvasUI
  
addChildUI(child:DisplayObject):ElementUI
add a child DisplayObject instance to the canvas and create a ElementUI instance
CanvasUI
  
contains(child:DisplayObject):Boolean
Determines whether or not the specified display object is a child of the CanvasUI container or the instance itself
CanvasUI
  
forceSizeContainer(width:Number, height:Number):void
function to force the size of the container (will update the scrollbars if used)
CanvasUI
  
getChildAt(index:int):DisplayObject
Returns the child display object instance that exists at the specified index
CanvasUI
  
getChildByName(name:String):DisplayObject
Returns the child display object that exists with the specified name
CanvasUI
  
getChildIndex(child:DisplayObject):int
Returns the index position of a child DisplayObject instance
CanvasUI
  
getChildUI(child:DisplayObject):ElementUI
get a child ElementUI instance
CanvasUI
  
get a child ElementUI instance using the name
CanvasUI
  
refresh(e:BaseEventUI = null):void
refresh the canvas elements and its children position
CanvasUI
  
removeChild(child:DisplayObject):DisplayObject
Removes the specified child DisplayObject instance from the child list of the CanvasUI container
CanvasUI
  
removeChildAt(index:int):DisplayObject
Removes a child DisplayObject from the specified index position in the child list of the DisplayObjectContainer
CanvasUI
  
removeChildUI(child:DisplayObject):void
remove a child from the BaseUI instance
CanvasUI
  
setChildIndex(child:DisplayObject, index:int):void
Changes the position of an existing child in the CanvasUI container
CanvasUI
  
swapChildren(child1:DisplayObject, child2:DisplayObject):void
Swaps the z-order (front-to-back order) of the two specified child objects
CanvasUI
  
swapChildrenAt(index1:int, index2:int):void
Swaps the z-order (front-to-back order) of the child objects at the two specified index positions in the child list.
CanvasUI
Property detail
alignXproperty
alignX:String  [read-write]

horizontal alignment when the property ratio is set to ElementUI.RATIO_IN or ElementUI.RATIO_OUT
can accept ElementUI.ALIGN_LEFT, ElementUI.ALIGN_RIGHT, ElementUI.ALIGN_CENTER

Implementation
    public function get alignX():String
    public function set alignX(value:String):void
alignYproperty 
alignY:String  [read-write]

vertical alignment when the property ratio is set to ElementUI.RATIO_IN or ElementUI.RATIO_OUT
can accept ElementUI.ALIGN_CENTER, ElementUI.ALIGN_TOP, ElementUI.ALIGN_BOTTOM

Implementation
    public function get alignY():String
    public function set alignY(value:String):void
baseUIproperty 
baseUI:BaseUI  [read-only]

get the instance of the BaseUI class, used for the children added with addChild or addChildUI

Implementation
    public function get baseUI():BaseUI
bottomproperty 
bottom:Number  [read-write]

bottom value (from the reference), Number or String

Implementation
    public function get bottom():Number
    public function set bottom(value:Number):void
buttonModeproperty 
buttonMode:Boolean  [read-write]

Specifies the button mode of this sprite

Implementation
    public function get buttonMode():Boolean
    public function set buttonMode(value:Boolean):void
bypassSizeproperty 
bypassSize:Boolean  [read-write]

whether or not the DisplayObject will be resized (not working with ratio set to RATIO_IN or RATIO_OUT)

Implementation
    public function get bypassSize():Boolean
    public function set bypassSize(value:Boolean):void
canvasAlphaproperty 
canvasAlpha:Number  [read-write]

background alpha of the canvas

The default value is Number 0.

Implementation
    public function get canvasAlpha():Number
    public function set canvasAlpha(value:Number):void
canvasColorproperty 
canvasColor:uint  [read-write]

background color of the canvas

The default value is uint 0x000000.

Implementation
    public function get canvasColor():uint
    public function set canvasColor(value:uint):void
containerproperty 
container:Sprite  [read-only]

get the instance of the container, it contains the children added with addChild and addChildUI

Implementation
    public function get container():Sprite
forceReferenceHeightproperty 
forceReferenceHeight:Number  [read-write]

force the height of the reference

Implementation
    public function get forceReferenceHeight():Number
    public function set forceReferenceHeight(value:Number):void
forceReferenceWidthproperty 
forceReferenceWidth:Number  [read-write]

force the width of the reference

Implementation
    public function get forceReferenceWidth():Number
    public function set forceReferenceWidth(value:Number):void
heightproperty 
height:Number  [read-write]

height of the canvas

Implementation
    public function get height():Number
    public function set height(value:Number):void
horizontalCenterproperty 
horizontalCenter:Number  [read-write]

horizontal center value (from the reference), Number or String

Implementation
    public function get horizontalCenter():Number
    public function set horizontalCenter(value:Number):void
initialWidthproperty 
initialWidth:Number  [read-write]

width of the DisplayObject when added to the BaseUI instance

Implementation
    public function get initialWidth():Number
    public function set initialWidth(value:Number):void
keepOnScreenproperty 
keepOnScreen:Boolean  [read-write]

keep a DisplayObject in the screen

Implementation
    public function get keepOnScreen():Boolean
    public function set keepOnScreen(value:Boolean):void
layoutMaskproperty 
layoutMask:Mask  [read-only]

get the instance of the mask

Implementation
    public function get layoutMask():Mask
leftproperty 
left:Number  [read-write]

left value (from the reference), Number or String

Implementation
    public function get left():Number
    public function set left(value:Number):void
mouseChildrenproperty 
mouseChildren:Boolean  [read-write]

Determines whether or not the children of the object are mouse enabled

Implementation
    public function get mouseChildren():Boolean
    public function set mouseChildren(value:Boolean):void
numChildrenproperty 
numChildren:int  [read-only]

Returns the number of children of the CanvasUI container

Implementation
    public function get numChildren():int
onStageproperty 
onStage:Boolean  [read-write]

set the stage as a reference to calculate position ans sizes, if false the parent will be the reference

Implementation
    public function get onStage():Boolean
    public function set onStage(value:Boolean):void
percentHeightproperty 
percentHeight:*  [write-only]

set the height percentage (will accept Number or String, with or without the percentage character

Implementation
    public function set percentHeight(value:*):void
percentWidthproperty 
percentWidth:*  [write-only]

set the width percentage (will accept Number or String, with or without the percentage character

Implementation
    public function set percentWidth(value:*):void
propertiesproperty 
properties:Object  [read-write]

Object to get or set the CanvasUI properties, for example:
element.properties = {top:0, bottom:"20", onStage:false, width:"50%"};

Implementation
    public function get properties():Object
    public function set properties(value:Object):void
ratioproperty 
ratio:String  [read-write]

type of ratio of the CanvasUI, can be ElementUI.RATIO_IN or ElementUI.RATIO_OUT
any other String will set the ratio to none
the following properties cannot be set or are not used a ratio has been specified:
x, y, width, height, horizontalCenter and verticalCenter

Implementation
    public function get ratio():String
    public function set ratio(value:String):void
referenceproperty 
reference:DisplayObjectContainer  [read-write]

specify a DisplayObjectContainer reference on which the size and position of the ElementUI will refer to
if not set, the onStage property value is the reference (onStage true = stage, onStage false = parent)

Implementation
    public function get reference():DisplayObjectContainer
    public function set reference(value:DisplayObjectContainer):void
rightproperty 
right:Number  [read-write]

right value (from the reference), Number or String

Implementation
    public function get right():Number
    public function set right(value:Number):void
scrollPaneproperty 
scrollPane:*  [read-only]

get the instance of the scrollpane used for the scrollbars
you must cast the return: Scrollpane(canvas.scrollpane), the wild card has been used not to import the SCrollpane classes if not used

Implementation
    public function get scrollPane():*
topproperty 
top:Number  [read-write]

top value (from the reference), Number or String

Implementation
    public function get top():Number
    public function set top(value:Number):void
uiproperty 
ui:ElementUI  [read-only]

get a the wrapper ElementUI instance

Implementation
    public function get ui():ElementUI
useInitialSizeproperty 
useInitialSize:Boolean  [read-write]

use the size that has been recorded when the DisplayObject has been added to the BaseUI instance
useful when a mask or other DisplayObject can disturb the real size of the DisplayObject

Implementation
    public function get useInitialSize():Boolean
    public function set useInitialSize(value:Boolean):void
verticalCenterproperty 
verticalCenter:Number  [read-write]

vertical center value (from the reference), Number or String

Implementation
    public function get verticalCenter():Number
    public function set verticalCenter(value:Number):void
widthproperty 
width:Number  [read-write]

width of the canvas

Implementation
    public function get width():Number
    public function set width(value:Number):void
wrapperproperty 
wrapper:Wrapper  [read-only]

get the instance of the wrapper

Implementation
    public function get wrapper():Wrapper
xproperty 
x:Number  [read-write]

x position of the canvas, Number or String

Implementation
    public function get x():Number
    public function set x(value:Number):void
yproperty 
y:Number  [read-write]

y position of the canvas

Implementation
    public function get y():Number
    public function set y(value:Number):void
Constructor detail
CanvasUI()constructor
public function CanvasUI(widthLayout:Number = 100, heightLayout:Number = 100, layoutScrollbar:Boolean = true, layoutMask:Boolean = true)

Constructor Create an instance of the CanvasUI class

Parameters
widthLayout:Number (default = 100) — width of the canvas
 
heightLayout:Number (default = 100) — height of the canvas
 
layoutScrollbar:Boolean (default = true) — whether or not the canvas creates and uses a mask to show only the content within the canvas
 
layoutMask:Boolean (default = true) — whether or not the canvas creates and uses scrollbars if the content is bigger than the canvas (scrollpane instance)
Method detail
addChild()method
public override function addChild(child:DisplayObject):DisplayObject

Adds a child DisplayObject instance to this CanvasUI container

Parameters
child:DisplayObject — DisplayObject

Returns
DisplayObject — DisplayObject
addChildAt()method 
public override function addChildAt(child:DisplayObject, index:int):DisplayObject

Adds a child DisplayObject instance to the CanvasUI container

Parameters
child:DisplayObject — DisplayObject
 
index:int — int depth

Returns
DisplayObject — DisplayObject
addChildUI()method 
public function addChildUI(child:DisplayObject):ElementUI

add a child DisplayObject instance to the canvas and create a ElementUI instance

Parameters
child:DisplayObject — DisplayObject

Returns
ElementUI — ElementUI instance of the DisplayObject
contains()method 
public override function contains(child:DisplayObject):Boolean

Determines whether or not the specified display object is a child of the CanvasUI container or the instance itself

Parameters
child:DisplayObject — DisplayObject

Returns
Boolean — Boolean
forceSizeContainer()method 
public function forceSizeContainer(width:Number, height:Number):void

function to force the size of the container (will update the scrollbars if used)

Parameters
width:Number — Number
 
height:Number — Number
getChildAt()method 
public override function getChildAt(index:int):DisplayObject

Returns the child display object instance that exists at the specified index

Parameters
index:int — int

Returns
DisplayObject — DisplayObject
getChildByName()method 
public override function getChildByName(name:String):DisplayObject

Returns the child display object that exists with the specified name

Parameters
name:String — String

Returns
DisplayObject — DisplayObject
getChildIndex()method 
public override function getChildIndex(child:DisplayObject):int

Returns the index position of a child DisplayObject instance

Parameters
child:DisplayObject — DisplayObject

Returns
int — int
getChildUI()method 
public function getChildUI(child:DisplayObject):ElementUI

get a child ElementUI instance

Parameters
child:DisplayObject — DisplayObject

Returns
ElementUI — ElementUI instance of the DisplayObject
getChildUIByName()method 
public function getChildUIByName(name:String):ElementUI

get a child ElementUI instance using the name

Parameters
name:String — String

Returns
ElementUI — ElementUI instance of the DisplayObject
refresh()method 
public function refresh(e:BaseEventUI = null):void

refresh the canvas elements and its children position

Parameters
e:BaseEventUI (default = null)
removeChild()method 
public override function removeChild(child:DisplayObject):DisplayObject

Removes the specified child DisplayObject instance from the child list of the CanvasUI container

Parameters
child:DisplayObject — DisplayObject

Returns
DisplayObject — DisplayObject
removeChildAt()method 
public override function removeChildAt(index:int):DisplayObject

Removes a child DisplayObject from the specified index position in the child list of the DisplayObjectContainer

Parameters
index:int — int

Returns
DisplayObject — DisplayObject
removeChildUI()method 
public function removeChildUI(child:DisplayObject):void

remove a child from the BaseUI instance

Parameters
child:DisplayObject — DisplayObject
setChildIndex()method 
public override function setChildIndex(child:DisplayObject, index:int):void

Changes the position of an existing child in the CanvasUI container

Parameters
child:DisplayObject — DisplayObject
 
index:int — int new depth
swapChildren()method 
public override function swapChildren(child1:DisplayObject, child2:DisplayObject):void

Swaps the z-order (front-to-back order) of the two specified child objects

Parameters
child1:DisplayObject — DisplayObject
 
child2:DisplayObject — DisplayObject
swapChildrenAt()method 
public override function swapChildrenAt(index1:int, index2:int):void

Swaps the z-order (front-to-back order) of the child objects at the two specified index positions in the child list.

Parameters
index1:int — int
 
index2:int — int