RectangleUtils

Kind of class:class
Inherits from:none
Author:Arthur Clemens
Classpath:org.asapframework.util.RectangleUtils
File last modified:Monday, 29 January 2007, 15:33:53

Summary


Class methods
  • getCenter (inRectangle:Rectangle) : Point
    • The center Point of the rectangle relative to its parent.
  • setCenter (inRectangle:Rectangle) : Void
  • rectOfMovieClip (inMC:MovieClip) : Rectangle
    • Returns the rectangle of the MovieClip's unscaled contents as a new Rectangle.
  • boundsOfMovieClip (inMC:MovieClip, inTargetSpace:MovieClip) : Rectangle
    • Returns the bounds (Stage coordinates) of a MovieClip as a new Rectangle - see MovieClip.getBounds.
  • setToBounds (inMC:MovieClip, inBounds:Rectangle) : Void
    • Sets the size and origin of a movieclip to the bounds of a Rectangle.
  • centerPointOfMovieClip (inMC:MovieClip, inTargetSpace:MovieClip) : Point
    • Returns the center point of the MovieClip's bounds.
  • centerToRectangle (r1:Rectangle) : Void
    • Utility fuction to set the center to another rectangle's center.
  • flattenHeight (inRectangle:Rectangle, inNewHeight:Number) : Void
    • Utility function to flatten the height of the Rectangle to a new given height.
  • flattenWidth (inRectangle:Rectangle, inNewWidth:Number) : Void
    • Utility function to flatten the width of the Rectangle to a new given width.

Class methods

boundsOfMovieClip

static function boundsOfMovieClip (
inMC:MovieClip, inTargetSpace:MovieClip) : Rectangle

Deprecated As of Flash 8: use var trans:Transform = new Transform(my_mc).pixelBounds to get the Rectangle bounds of a movieclip.
Returns the bounds (Stage coordinates) of a MovieClip as a new Rectangle - see MovieClip.getBounds. When a movieclip is scaled, this method returns the scaled clip sizes.
Parameters:
inMc :
the MovieClip to be measured
inTargetSpace:
the target path of the Timeline whose coordinate system you want to use as a reference point; if null, _level0 is assumed
Returns:
  • A new Rectangle that has the size of the MovieClip and the position of the clip on the Stage.
Implementation note:
  • Calls MovieClip.getBounds.
Usage note:
  • A newly created movieclip without any contents has these bounds: (x=6710886.35, y=6710886.35, w=0, h=0)

centerPointOfMovieClip

static function centerPointOfMovieClip (
inMC:MovieClip, inTargetSpace:MovieClip) : Point

Returns the center point of the MovieClip's bounds.
Parameters:
inMc :
the MovieClip to be measured
inTargetSpace:
the target path of the Timeline whose coordinate system you want to use as a reference point; if null, _level0 is assumed; pass the movieclip to get the center of its contents
Returns:
  • A new Point that has the position of the center of the MovieClip bounds. Returns Point(0,0) if the clip bounding rectangle has no width or heigth.
Implementation note:
Usage note:
  • A newly created movieclip without any contents has these bounds: (x=6710886.35, y=6710886.35, w=0, h=0); the center of this movieclip will be returned as Point (0,0)
  • To get the relative center point (the center of a movieclip's contents), write centerPointOfMovieClip(my_mc, my_mc)
Example:
  • var mc:MovieClip = _level0.createEmptyMovieClip("box", 1);
    var size:Number = 100;
    with (mc) {
        lineStyle( 0, 0x000000, 100 );
        moveTo( 0, 0 );
        lineTo( 0, size );
        lineTo( size, size );
        lineTo( size, 0 );
        lineTo( 0, 0 );
    }
    mc._x = 300;
    mc._y = 200;
    trace(RectangleUtils.centerPointOfMovieClip(mc); // ((x=350, y=250)
    trace(RectangleUtils.centerPointOfMovieClip(mc,mc); // (x=50, y=50)

centerToRectangle

static function centerToRectangle (
r1:Rectangle, r2:Rectangle) : Void

Utility fuction to set the center to another rectangle's center.
Parameters:
r1:
the rectangle to set the center to
r2:
the rectangle to get the center of
Example:
  • var rect1:Rectangle = new Rectangle(0,0,20,20);
    var rect2:Rectangle = new Rectangle(50,50,40,40);
    
    trace("rect1 = " + rect1); // (x=0, y=0, w=20, h=20)
    trace("rect2 = " + rect2); // (x=50, y=50, w=40, h=40)
    
    RectangleUtils.centerToRectangle(rect1, rect2);
    
    trace("rect1 = " + rect1); // (x=60, y=60, w=20, h=20)
    trace("rect2 = " + rect2); // (x=50, y=50, w=40, h=40)

flattenHeight

static function flattenHeight (
inRectangle:Rectangle, inNewHeight:Number) : Void

Utility function to flatten the height of the Rectangle to a new given height. In contrast to org.asapframework.util.types.Rectangle.height flattenHeight originates from the center.
Parameters:
inRectangle:
the Rectangle to flatten the height of
inNewHeight:
the new height of the Rectangle

flattenWidth

static function flattenWidth (
inRectangle:Rectangle, inNewWidth:Number) : Void

Utility function to flatten the width of the Rectangle to a new given width. In contrast to org.asapframework.util.types.Rectangle.width flattenWidth originates from the center.
Parameters:
inRectangle:
the Rectangle to flatten the width of
inNewWidth :
the new width of the Rectangle

getCenter

static function getCenter (
inRectangle:Rectangle) : Point

The center Point of the rectangle relative to its parent.
Parameters:
inRectangle:
the Rectangle to get the center point of
Example:
  • var rectangle:Rectangle = new Rectangle(1,2,4,8);
    // the rectangle has width:4 and height:8
    var center:Point = RectangleUtils.getCenter(rectangle);
    trace(center);
    // (x=3, y=6)

rectOfMovieClip

static function rectOfMovieClip (
inMC:MovieClip) : Rectangle

Returns the rectangle of the MovieClip's unscaled contents as a new Rectangle. When a movieclip is scaled, this method returns the unscaled clip sizes.
Parameters:
inMc:
the MovieClip to be measured
Returns:
  • A new Rectangle that has the size of the MovieClip and the position of its contents. Returns an empty Rectangle when an empty movieclip without any contents is passed.
Implementation note:

setCenter

static function setCenter (
inRectangle:Rectangle, inPoint:Point) : Void

setToBounds

static function setToBounds (
inMC:MovieClip, inBounds:Rectangle) : Void

Sets the size and origin of a movieclip to the bounds of a Rectangle.
Parameters:
inMC :
the movieclip to set the size and origin of
inBounds:
the Rectangle which size and origin to use