Packagecom.afcomponents.umap.types
Classpublic class Align

Align class provides an interface to save & align objects with each other.

To use the Align class you should first create it's instance where you should specify horizontal and vertical alignment. Then you should use applyTo() method, where you should pass a Display object you wish to align and a target DisplayObject, Point or Bounds instance you wish to align with. Additionally you can specify distance to offset the final alignment position and padding to use within the bounds of the target alignment object.

Horizontal alignment can be set to one of the following constants values:

  • Align.LEFT (default)
  • Align.CENTER
  • Align.RIGHT
  • Vertical alignment can be set to one of the following constants values:

  • Align.TOP (default)
  • Align.MIDDLE
  • Align.BOTTOM

  • Example
    Here is a quick usage example:
     import com.afcomponents.umap.types.Align;
     import flash.display.Sprite;
      
     // create target mc
     var target:Sprite = new Sprite();
     addChild(target);
     // draw red frame
     target.graphics.lineStyle(1,0xFF0000);
     target.graphics.drawRect(0,0,200,200);
     target.x = target.y = 100;
      
     // create mc, which needs to be aligned
     var mc:Sprite = new Sprite();
     addChild(mc);
     // draw blue box
     mc.graphics.lineStyle(1, 0x0);
     mc.graphics.beginFill(0xABD6FE);
     mc.graphics.drawRect(0,0,100,100);
      
     // create new Align object & apply alignment
     var align:Align = new Align(Align.CENTER, Align.MIDDLE);
     align.applyTo(mc, target); // you should see a blue box centered inside a red frame
     

    See also

    applyTo()
    Offset
    Bounds
    flash.display.DisplayObject
    flash.geom.Point


    Public Properties
     PropertyDefined by
      horizontal : String
    Gets or sets the horizontal alignment.
    Align
      vertical : String
    Gets or sets the vertical alignment.
    Align
    Public Methods
     MethodDefined by
      
    Align(horizontal:String = null, vertical:String = null)
    Align constructor.
    Align
      
    applyTo(mc:DisplayObject, target:Offset, offset:Point = null, padding:* = null):Boolean
    Applies current alignment object to align specified DisplayObject with a target object.
    Align
      
    Creates a copy of this Align object.
    Align
      
    equals(other:Align):Boolean
    Determines whether two Align objects are equal.
    Align
      
    fromString(str:String):Align
    [static] Creates new Align object from the alignment String written as both horizontal & vertical alignment values separated by a dash sign.
    Align
      
    [static] Returns new object, which will be constructed from the source XML data.
    Align
      
    getXMLFromType(align:Align, name:String):XML
    [static] Returns XML data that describes the Object.
    Align
      
    toString():String
    Returns a String that represents horizontal & vertical alignment stored in this object.
    Align
    Public Constants
     ConstantDefined by
      BOTTOM : String = "bottom"
    [static] The Align.BOTTOM constant defines the value of the vertical property of the Align object that indicates bottom vertical alignment.
    Align
      CENTER : String = "center"
    [static] The Align.CENTER constant defines the value of the horizontal property of the Align object that indicates central horizontal alignment.
    Align
      DEFAULT_NODE_NAME : String = "align"
    [static] Defines default root node name for XML conversion.
    Align
      LEFT : String = "left"
    [static] The Align.LEFT constant defines the value of the horizontal property of the Align object that indicates left-handed horizontal alignment.
    Align
      MIDDLE : String = "middle"
    [static] The Align.MIDDLE constant defines the value of the vertical property of the Align object that indicates middle vertical alignment.
    Align
      RIGHT : String = "right"
    [static] The Align.RIGHT constant defines the value of the horizontal property of the Align object that indicates right-handed horizontal alignment.
    Align
      TOP : String = "top"
    [static] The Align.TOP constant defines the value of the vertical property of the Align object that indicates top vertical alignment.
    Align
    Property detail
    horizontalproperty
    horizontal:String  [read-write]

    Gets or sets the horizontal alignment. Possible values are: Align.LEFT, Align.CENTER or Align.RIGHT.

    Change of this property doesn't automatically realigns objects. Please use applyTo() method.

    The default value is Align.LEFT.

    Implementation
        public function get horizontal():String
        public function set horizontal(value:String):void

    See also

    verticalproperty 
    vertical:String  [read-write]

    Gets or sets the vertical alignment. Possible values are: Align.TOP, Align.MIDDLE or Align.BOTTOM.

    Change of this property doesn't automatically realigns objects. Please use applyTo() method.

    The default value is Align.TOP.

    Implementation
        public function get vertical():String
        public function set vertical(value:String):void

    See also

    Constructor detail
    Align()constructor
    public function Align(horizontal:String = null, vertical:String = null)

    Align constructor.

    Constructs new Align object that can be used to align objects with each other. You can additionally specify horizontal and vertical alignment. Use applyTo() method to apply current alignment to a DisplayObject.

    Horizontal alignment can be set to one of the following constants values:

  • Align.LEFT (the default)
  • Align.CENTER
  • Align.RIGHT
  • Vertical alignment can be set to one of the following constants values:

  • Align.TOP (the default)
  • Align.MIDDLE
  • Align.BOTTOM
  • Parameters
    horizontal:String (default = null) — Defines horizontal alignment
     
    vertical:String (default = null) — Defines vertical alignment

    See also

    applyTo()
    flash.display.DisplayObject
    Method detail
    applyTo()method
    public function applyTo(mc:DisplayObject, target:Offset, offset:Point = null, padding:* = null):Boolean

    Applies current alignment object to align specified DisplayObject with a target object.

    Additionally you can specify alignment offset & padding. Here is how it works:

    Parameters
    mc:DisplayObject — DisplayObject that needs to be aligned.
     
    target:Offset — Target object that we wish to align with. Can be one of the following: DisplayObject, Bounds object, Size object or a Point.
     
    offset:Point (default = null) — An Offset object that specifies distance to offset final alignement position. &
     
    padding:* (default = null) — Specifies padding from the boundaries of target DisplayObject.

    Returns
    Boolean — Value of true if alignment was succesfull; false if it was not.

    See also

    Offset
    Bounds
    Size
    flash.display.DisplayObject
    flash.geom.Point

    Example
    Suppose you have this code to align a box inside a frame:
      import com.afcomponents.umap.types.Align;
      import com.afcomponents.umap.types.Offset;
      import flash.display.Sprite;
      import flash.geom.Point;
       
      // create target mc
      var target:Sprite = new Sprite();
      addChild(target);
      // draw red rectangle
      target.graphics.lineStyle(1,0xFF0000);
      target.graphics.drawRect(0,0,200,200);
      target.x = target.y = 100;
       
      // create mc, which needs to be aligned
      var mc:Sprite = new Sprite();
      addChild(mc);
      // draw blue box
      mc.graphics.lineStyle(1, 0x0);
      mc.graphics.beginFill(0xABD6FE);
      mc.graphics.drawRect(0,0,100,100);
       
      // create new Align object & apply alignment
      var align:Align = new Align(Align.CENTER, Align.BOTTOM);
      var offset:Offset = new Offset(-20,-10);
      var padding:Point = new Point(10, 20);
      align.applyTo(mc, target, offset, padding);
      

    The applyTo() method works in 3 steps:
    1. Aligns object withtin the bounds of target DispalyObject based on vertical & horizontal alignment.
    2. Applies padding.
    3. Calculates & applies offset.

    Alignment explained

    clone()method 
    public function clone():Align

    Creates a copy of this Align object.

    Returns
    Align — A copy of this object.
    equals()method 
    public function equals(other:Align):Boolean

    Determines whether two Align objects are equal.

    Two Align objects are equal if all parameters in this object are equal to the parameters of the other.

    Parameters
    other:Align — The object to be compared.

    Returns
    Boolean — A value of true if object is equal to this Align object; false if it is not.
    fromString()method 
    public static function fromString(str:String):Align

    Creates new Align object from the alignment String written as both horizontal & vertical alignment values separated by a dash sign. Order in which these alignments are written is unimportant.

    Parameters
    str:String

    Returns
    Align — New Align object

    Example
      import com.afcomponents.umap.types.Align;
      var align:Align = Align.fromString("right-top");
      trace (align); // traces (horizonal=right, vertical=top)
      align = null;
      align = Align.fromString("top-right");
      trace (align); // traces (horizonal=right, vertical=top)

    getTypeFromXML()method 
    public static function getTypeFromXML(xml:XML):Align

    Returns new object, which will be constructed from the source XML data.

    Parameters
    xml:XML — Source XML data.

    Returns
    Align — Object that was constructed from the source XML data.
    getXMLFromType()method 
    public static function getXMLFromType(align:Align, name:String):XML

    Returns XML data that describes the Object. You can also specify root node name in the second parameter.

    Parameters
    align:Align — Object that should be converted to XML.
     
    name:String — Root node name.

    Returns
    XML — XML data that describes the properties of the source object.
    toString()method 
    public function toString():String

    Returns a String that represents horizontal & vertical alignment stored in this object.

    The output will look like "(horizonal=horizontal alignment, vertical=vertical alignment)"

    Returns
    String — A textual representation of this Align object.
    Constant detail
    BOTTOMconstant
    public static const BOTTOM:String = "bottom"

    The Align.BOTTOM constant defines the value of the vertical property of the Align object that indicates bottom vertical alignment.

    CENTERconstant 
    public static const CENTER:String = "center"

    The Align.CENTER constant defines the value of the horizontal property of the Align object that indicates central horizontal alignment.

    DEFAULT_NODE_NAMEconstant 
    public static const DEFAULT_NODE_NAME:String = "align"

    Defines default root node name for XML conversion.

    LEFTconstant 
    public static const LEFT:String = "left"

    The Align.LEFT constant defines the value of the horizontal property of the Align object that indicates left-handed horizontal alignment.

    MIDDLEconstant 
    public static const MIDDLE:String = "middle"

    The Align.MIDDLE constant defines the value of the vertical property of the Align object that indicates middle vertical alignment.

    RIGHTconstant 
    public static const RIGHT:String = "right"

    The Align.RIGHT constant defines the value of the horizontal property of the Align object that indicates right-handed horizontal alignment.

    TOPconstant 
    public static const TOP:String = "top"

    The Align.TOP constant defines the value of the vertical property of the Align object that indicates top vertical alignment.