| Package | com.afcomponents.umap.types |
| Class | public class Align |
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:
Vertical alignment can be set to one of the following constants values:
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
| Property | Defined by | ||
|---|---|---|---|
| horizontal : String
Gets or sets the horizontal alignment.
| Align | ||
| vertical : String
Gets or sets the vertical alignment.
| Align | ||
| Method | Defined by | ||
|---|---|---|---|
|
Align(horizontal:String = null, vertical:String = null)
Align constructor.
| Align | ||
|
Applies current alignment object to align specified DisplayObject with a target object.
| Align | ||
|
Creates a copy of this Align object.
| Align | ||
|
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 | ||
|
getTypeFromXML(xml:XML):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 | ||
| Constant | Defined 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 | ||
| horizontal | property |
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.
public function get horizontal():String
public function set horizontal(value:String):void
See also
| vertical | property |
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.
public function get vertical():String
public function set vertical(value:String):void
See also
| 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:
Vertical alignment can be set to one of the following constants values:
horizontal:String (default = null) — Defines horizontal alignment
|
|
vertical:String (default = null) — Defines vertical alignment
|
See also
| applyTo | () | method |
public function applyTo(mc:DisplayObject, target:Offset, offset:Point = null, padding:* = null):BooleanApplies current alignment object to align specified DisplayObject with a target object.
Additionally you can specify alignment offset & padding. Here is how it works:
Parametersmc: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.
|
Boolean — Value of true if alignment was succesfull; false if it was not.
|
See also
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);
applyTo() method works in 3 steps:
| clone | () | method |
public function clone():AlignCreates a copy of this Align object.
ReturnsAlign —
A copy of this object.
|
| equals | () | method |
public function equals(other:Align):BooleanDetermines 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.
Parametersother:Align — The object to be compared.
|
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.
str:String |
Align —
New Align object
|
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):AlignReturns new object, which will be constructed from the source XML data.
Parametersxml:XML — Source XML data.
|
Align —
Object that was constructed from the source XML data.
|
| getXMLFromType | () | method |
public static function getXMLFromType(align:Align, name:String):XMLReturns XML data that describes the Object. You can also specify root node name in the second parameter.
Parametersalign:Align — Object that should be converted to XML.
|
|
name:String — Root node name.
|
XML — XML data that describes the properties of the source object.
|
| toString | () | method |
public function toString():StringReturns a String that represents horizontal & vertical alignment stored in this object.
The output will look like "(horizonal=horizontal alignment, vertical=vertical alignment)"
ReturnsString — A textual representation of this Align object.
|
| BOTTOM | constant |
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.
| CENTER | constant |
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_NAME | constant |
public static const DEFAULT_NODE_NAME:String = "align"Defines default root node name for XML conversion.
| LEFT | constant |
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.
| MIDDLE | constant |
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.
| RIGHT | constant |
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.
| TOP | constant |
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.