AlignUtil
Kind of class: | public class |
---|---|
Package: | |
Inherits from: |
|
Version: | 05/19/11 |
Author: | Aaron Clinger, Jon Adams |
Classpath: | org.casalib.util.AlignUtil |
File last modified: | Friday, 20 May 2011, 00:59:45 |
/* CASA Lib for ActionScript 3.0 Copyright (c) 2011, Aaron Clinger & Contributors of CASA Lib All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the CASA Lib nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.casalib.util { import flash.display.DisplayObject; import flash.geom.Point; import flash.geom.Rectangle; import org.casalib.util.DisplayObjectUtil; /** Provides utility functions for aligning. @author Aaron Clinger @author Jon Adams @version 05/19/11 */ public class AlignUtil { public static const BOTTOM:String = 'bottom'; public static const BOTTOM_CENTER:String = 'bottomCenter'; public static const BOTTOM_LEFT:String = 'bottomLeft'; public static const BOTTOM_RIGHT:String = 'bottomRight'; public static const CENTER:String = 'center'; public static const LEFT:String = 'left'; public static const MIDDLE:String = 'middle'; public static const MIDDLE_CENTER:String = 'middleCenter'; public static const MIDDLE_LEFT:String = 'middleLeft'; public static const MIDDLE_RIGHT:String = 'middleRight'; public static const RIGHT:String = 'right'; public static const TOP:String = 'top'; public static const TOP_CENTER:String = 'topCenter'; public static const TOP_LEFT:String = 'topLeft'; public static const TOP_RIGHT:String = 'topRight'; /** Aligns aDisplayObject
to the boundingRectangle
acording to the defined alignment. @param alignment: The alignment type/position. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function align(alignment:String, displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { const offsetPosition:Point = DisplayObjectUtil.getOffsetPosition(displayObject); switch (alignment) { case AlignUtil.TOP : case AlignUtil.MIDDLE : case AlignUtil.BOTTOM : break; default : displayObject.x = offsetPosition.x; } switch (alignment) { case AlignUtil.LEFT : case AlignUtil.CENTER : case AlignUtil.RIGHT : break; default : displayObject.y = offsetPosition.y; } const alignPosition:Point = AlignUtil._getPosition(alignment, displayObject.width, displayObject.height, bounds, outside); const relPosition:Rectangle = displayObject.getBounds((targetCoordinateSpace == null) ? displayObject : targetCoordinateSpace); switch (alignment) { case AlignUtil.TOP : case AlignUtil.MIDDLE : case AlignUtil.BOTTOM : break; default : displayObject.x += alignPosition.x - relPosition.x; if (snapToPixel) displayObject.x = Math.round(displayObject.x); } switch (alignment) { case AlignUtil.LEFT : case AlignUtil.CENTER : case AlignUtil.RIGHT : break; default : displayObject.y += alignPosition.y - relPosition.y; if (snapToPixel) displayObject.y = Math.round(displayObject.y); } } /** Aligns aRectangle
to anotherRectangle
. @param align: The alignment type/position. @param rectangle: TheRectangle
to align. @param bounds: The area in which to align theRectangle
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theRectangle
be positioned on sub-pixelsfalse
. @param outside: Align theRectangle
to the outside of the boundstrue
, or the insidefalse
. @return A new alignedRectangle
. */ public static function alignRectangle(alignment:String, rectangle:Rectangle, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false):Rectangle { const alignedRectangle:Rectangle = rectangle.clone(); alignedRectangle.offsetPoint(AlignUtil._getPosition(alignment, rectangle.width, rectangle.height, bounds, outside)); if (snapToPixel) { alignedRectangle.x = Math.round(alignedRectangle.x); alignedRectangle.y = Math.round(alignedRectangle.y); } return alignedRectangle; } /** Aligns aDisplayObject
to the nearest Pixel. @param displayObject: TheDisplayObject
to align. */ public static function alignToPixel(displayObject:DisplayObject):void { displayObject.x = Math.round(displayObject.x); displayObject.y = Math.round(displayObject.y); } /** Aligns aDisplayObject
to the bottom of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignBottom(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.BOTTOM, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the bottom left of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignBottomLeft(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.BOTTOM_LEFT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the bottom and horizontal center of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignBottomCenter(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.BOTTOM_CENTER, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the bottom right of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignBottomRight(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.BOTTOM_RIGHT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the horizontal center of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignCenter(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.CENTER, displayObject, bounds, snapToPixel, false, targetCoordinateSpace); } /** Aligns aDisplayObject
to the left side of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignLeft(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.LEFT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the vertical middle of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignMiddle(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.MIDDLE, displayObject, bounds, snapToPixel, false, targetCoordinateSpace); } /** Aligns aDisplayObject
to the vertical middle and left side of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignMiddleLeft(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.MIDDLE_LEFT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the vertical middle and horizontal center of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignMiddleCenter(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.MIDDLE_CENTER, displayObject, bounds, snapToPixel, false, targetCoordinateSpace); } /** Aligns aDisplayObject
to the vertical middle and right side of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignMiddleRight(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.MIDDLE_RIGHT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the right side of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignRight(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.RIGHT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the top of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignTop(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.TOP, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the top left of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignTopLeft(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.TOP_LEFT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the top side and horizontal center of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignTopCenter(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.TOP_CENTER, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } /** Aligns aDisplayObject
to the top right of the boundingRectangle
. @param displayObject: TheDisplayObject
to align. @param bounds: The area in which to align theDisplayObject
. @param snapToPixel: Force the position to whole pixelstrue
, or to let theDisplayObject
be positioned on sub-pixelsfalse
. @param outside: Align theDisplayObject
to the outside of the boundstrue
, or the insidefalse
. @param targetCoordinateSpace: The display object that defines the coordinate system to use. Specify if thedisplayObject
is not in the same scope as the desired coordinate space, ornull
to use thedisplayObject
's coordinate space. */ public static function alignTopRight(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null):void { AlignUtil.align(AlignUtil.TOP_RIGHT, displayObject, bounds, snapToPixel, outside, targetCoordinateSpace); } protected static function _getPosition(alignment:String, targetWidth:uint, targetHeight:uint, bounds:Rectangle, outside:Boolean):Point { const position:Point = new Point(); switch (alignment) { case AlignUtil.BOTTOM_LEFT : case AlignUtil.LEFT : case AlignUtil.MIDDLE_LEFT : case AlignUtil.TOP_LEFT : position.x = outside ? bounds.x - targetWidth : bounds.x; break; case AlignUtil.BOTTOM_CENTER : case AlignUtil.CENTER : case AlignUtil.MIDDLE_CENTER : case AlignUtil.TOP_CENTER : position.x = (bounds.width - targetWidth) * 0.5 + bounds.x; break; case AlignUtil.BOTTOM_RIGHT: case AlignUtil.MIDDLE_RIGHT: case AlignUtil.RIGHT: case AlignUtil.TOP_RIGHT: position.x = outside ? bounds.right : bounds.right - targetWidth; break; } switch (alignment) { case AlignUtil.TOP: case AlignUtil.TOP_CENTER: case AlignUtil.TOP_LEFT: case AlignUtil.TOP_RIGHT: position.y = outside ? bounds.y - targetHeight : bounds.y; break; case AlignUtil.MIDDLE : case AlignUtil.MIDDLE_CENTER : case AlignUtil.MIDDLE_LEFT : case AlignUtil.MIDDLE_RIGHT : position.y = (bounds.height - targetHeight) * 0.5 + bounds.y; break; case AlignUtil.BOTTOM: case AlignUtil.BOTTOM_CENTER: case AlignUtil.BOTTOM_LEFT: case AlignUtil.BOTTOM_RIGHT: position.y = outside ? bounds.bottom : bounds.bottom - targetHeight; break; } return position; } } }
Summary
- BOTTOM : String
- BOTTOM_CENTER : String
- BOTTOM_LEFT : String
- BOTTOM_RIGHT : String
- CENTER : String
- LEFT : String
- MIDDLE : String
- MIDDLE_CENTER : String
- MIDDLE_LEFT : String
- MIDDLE_RIGHT : String
- RIGHT : String
- TOP : String
- TOP_CENTER : String
- TOP_LEFT : String
- TOP_RIGHT : String
-
align
(alignment:String, displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the bounding Rectangle acording to the defined alignment.
-
alignRectangle
(alignment:String, rectangle:Rectangle, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false) : Rectangle
- Aligns a Rectangle to another Rectangle.
-
alignToPixel
(displayObject:DisplayObject) : void
- Aligns a DisplayObject to the nearest Pixel.
-
alignBottom
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the bottom of the bounding Rectangle.
-
alignBottomLeft
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the bottom left of the bounding Rectangle.
-
alignBottomCenter
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the bottom and horizontal center of the bounding Rectangle.
-
alignBottomRight
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the bottom right of the bounding Rectangle.
-
alignCenter
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the horizontal center of the bounding Rectangle.
-
alignLeft
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the left side of the bounding Rectangle.
-
alignMiddle
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the vertical middle of the bounding Rectangle.
-
alignMiddleLeft
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the vertical middle and left side of the bounding Rectangle.
-
alignMiddleCenter
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the vertical middle and horizontal center of the bounding Rectangle.
-
alignMiddleRight
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the vertical middle and right side of the bounding Rectangle.
-
alignRight
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the right side of the bounding Rectangle.
-
alignTop
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the top of the bounding Rectangle.
-
alignTopLeft
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the top left of the bounding Rectangle.
-
alignTopCenter
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the top side and horizontal center of the bounding Rectangle.
-
alignTopRight
(displayObject:DisplayObject, bounds:Rectangle, snapToPixel:Boolean = true, outside:Boolean = false, targetCoordinateSpace:DisplayObject = null) : void
- Aligns a DisplayObject to the top right of the bounding Rectangle.
Constants
BOTTOM
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
LEFT
MIDDLE
MIDDLE_CENTER
MIDDLE_LEFT
MIDDLE_RIGHT
RIGHT
TOP
TOP_CENTER
TOP_LEFT
TOP_RIGHT
Class methods
align
Aligns a DisplayObject
to the bounding Rectangle
acording to the defined alignment.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignBottom
Aligns a DisplayObject
to the bottom of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignBottomCenter
Aligns a DisplayObject
to the bottom and horizontal center of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignBottomLeft
Aligns a DisplayObject
to the bottom left of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignBottomRight
Aligns a DisplayObject
to the bottom right of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignCenter
Aligns a DisplayObject
to the horizontal center of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignLeft
Aligns a DisplayObject
to the left side of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignMiddle
Aligns a DisplayObject
to the vertical middle of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignMiddleCenter
Aligns a DisplayObject
to the vertical middle and horizontal center of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignMiddleLeft
Aligns a DisplayObject
to the vertical middle and left side of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignMiddleRight
Aligns a DisplayObject
to the vertical middle and right side of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignRectangle
Aligns a Rectangle
to another Rectangle
.
Rectangle
to align. Rectangle
. true
, or to let the Rectangle
be positioned on sub-pixels false
. Rectangle
to the outside of the bounds true
, or the inside false
. -
A new aligned
Rectangle
.
alignRight
Aligns a DisplayObject
to the right side of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignToPixel
Aligns a DisplayObject
to the nearest Pixel.
DisplayObject
to align. alignTop
Aligns a DisplayObject
to the top of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignTopCenter
Aligns a DisplayObject
to the top side and horizontal center of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignTopLeft
Aligns a DisplayObject
to the top left of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space. alignTopRight
Aligns a DisplayObject
to the top right of the bounding Rectangle
.
DisplayObject
to align. DisplayObject
. true
, or to let the DisplayObject
be positioned on sub-pixels false
. DisplayObject
to the outside of the bounds true
, or the inside false
. displayObject
is not in the same scope as the desired coordinate space, or null
to use the displayObject
's coordinate space.