Packagecom.greensock.motionPaths
Classpublic class RectanglePath2D
InheritanceRectanglePath2D Inheritance MotionPath Inheritance flash.display.Shape

A RectanglePath2D defines a rectangular path on which a PathFollower can be placed, making it simple to tween objects along a rectangle's perimeter. A PathFollower's position along the path is described using its progress property, a value between 0 and 1 where 0 is at the beginning of the path (top left corner), and as the value increases, it moves clockwise along the path so that 0.5 would be at the lower right corner, and 1 is all the way back at the upper left corner of the path. So to tween a PathFollower along the path, you can simply tween its progress property. To tween ALL of the followers on the path at once, you can tween the RectanglePath2D's progress property. PathFollowers automatically wrap so that if the progress value exceeds 1 it continues at the beginning of the path.

Since RectanglePath2D extends the Shape class, you can add an instance to the display list to see a line representation of the path drawn which can be helpful especially during the production phase. Use lineStyle() to adjust the color, thickness, and other attributes of the line that is drawn (or set the RectanglePath2D's visible property to false or don't add it to the display list if you don't want to see the line at all). You can also adjust all of its properties like scaleX, scaleY, rotation, width, height, x, and y. That means you can tween those values as well to achieve very dynamic, complex effects with ease.


Example
Example AS3 code:
import com.greensock.*;
import com.greensock.motionPaths.*;

//create a rectangular motion path at coordinates x:25, y:25 with a width of 150 and a height of 100
var rect:RectanglePath2D = new RectanglePath2D(25, 25, 150, 100, false);

//position the MovieClip "mc" at the beginning of the path (upper left corner), and reference the resulting PathFollower instance with a "follower" variable.
var follower:PathFollower = rect.addFollower(mc, 0);

//tween the follower clockwise along the path all the way to the end, one full revolution
TweenLite.to(follower, 2, {progress:1});

//tween the follower counter-clockwise by using a negative progress value
TweenLite.to(follower, 2, {progress:-1});
NOTES
Copyright 2010, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.



Public Properties
 PropertyDefined by
  centerOrigin : Boolean
height of the rectangle in its unrotated, unscaled state (does not factor in any transformations like scaleX/scaleY/rotation)
RectanglePath2D
 Inheritedfollowers : Array
Returns an array of all PathFollower instances associated with this path
MotionPath
 Inheritedheight : Number
MotionPath
 Inheritedprogress : Number
A value (typically between 0 and 1) that can be used to move all followers along the path.
MotionPath
  rawHeight : Number
height of the rectangle in its unrotated, unscaled state (does not factor in any transformations like scaleX/scaleY/rotation)
RectanglePath2D
  rawWidth : Number
width of the rectangle in its unrotated, unscaled state (does not factor in any transformations like scaleX/scaleY/rotation)
RectanglePath2D
 Inheritedrotation : Number
MotionPath
 InheritedscaleX : Number
MotionPath
 InheritedscaleY : Number
MotionPath
 Inheritedtargets : Array
Returns an array of all target instances associated with the PathFollowers of this path
MotionPath
 Inheritedvisible : Boolean
MotionPath
 Inheritedwidth : Number
MotionPath
 Inheritedx : Number
MotionPath
 Inheritedy : Number
MotionPath
Public Methods
 MethodDefined by
  
RectanglePath2D(x:Number, y:Number, rawWidth:Number, rawHeight:Number, centerOrigin:Boolean = false)
Constructor
RectanglePath2D
 Inherited
addFollower(target:*, progress:Number = 0, autoRotate:Boolean = false, rotationOffset:Number = 0):PathFollower
Adds a follower to the path, optionally setting it to a particular progress position.
MotionPath
 Inherited
distribute(targets:Array = null, min:Number = 0, max:Number = 1, autoRotate:Boolean = false, rotationOffset:Number = 0):void
Distributes objects evenly along the MotionPath.
MotionPath
 Inherited
getFollower(target:Object):PathFollower
Returns the PathFollower instance associated with a particular target or null if none exists.
MotionPath
 Inherited
lineStyle(thickness:Number = 1, color:uint = 0x666666, alpha:Number = 1, pixelHinting:Boolean = false, scaleMode:String = "none", caps:String = null, joints:String = null, miterLimit:Number = 3, skipRedraw:Boolean = false):void
Sets the line style for the path which you will only see if you add the path to the display list with something like addChild() and make sure the visible property is true.
MotionPath
 Inherited
Removes all followers.
MotionPath
 Inherited
removeFollower(target:*):void
Removes the target as a follower.
MotionPath
  
renderObjectAt(target:Object, progress:Number, autoRotate:Boolean = false, rotationOffset:Number = 0):void
Positions any object with x and y properties on the path at a specific progress position.
RectanglePath2D
Property detail
centerOriginproperty
centerOrigin:Boolean  [read-write]

height of the rectangle in its unrotated, unscaled state (does not factor in any transformations like scaleX/scaleY/rotation)

Implementation
    public function get centerOrigin():Boolean
    public function set centerOrigin(value:Boolean):void
rawHeightproperty 
rawHeight:Number  [read-write]

height of the rectangle in its unrotated, unscaled state (does not factor in any transformations like scaleX/scaleY/rotation)

Implementation
    public function get rawHeight():Number
    public function set rawHeight(value:Number):void
rawWidthproperty 
rawWidth:Number  [read-write]

width of the rectangle in its unrotated, unscaled state (does not factor in any transformations like scaleX/scaleY/rotation)

Implementation
    public function get rawWidth():Number
    public function set rawWidth(value:Number):void
Constructor detail
RectanglePath2D()constructor
public function RectanglePath2D(x:Number, y:Number, rawWidth:Number, rawHeight:Number, centerOrigin:Boolean = false)

Constructor

Parameters
x:Number — The x coordinate of the origin of the rectangle (typically its top left corner unless centerOrigin is true)
 
y:Number — The y coordinate of the origin of the rectangle (typically its top left corner unless centerOrigin is true)
 
rawWidth:Number — The width of the rectangle in its unrotated and unscaled state
 
rawHeight:Number — The height of the rectangle in its unrotated and unscaled state
 
centerOrigin:Boolean (default = false) — To position the origin (registration point around which transformations occur) at the center of the rectangle instead of its upper left corner, set centerOrigin to true (it is false by default).
Method detail
renderObjectAt()method
public override function renderObjectAt(target:Object, progress:Number, autoRotate:Boolean = false, rotationOffset:Number = 0):void

Positions any object with x and y properties on the path at a specific progress position. For example, to position mc in the middle of the path, you would do:

myPath.renderObjectAt(mc, 0.5);

Some paths have methods to translate other meaningful information into a progress value, like for a CirclePath2D you can get the progress associated with the 90-degree position with the angleToPosition() method like this:

myCircle.renderObjectAt(mc, myCircle.angleToProgress(90));

Parameters
target:Object — The target object to position
 
progress:Number — The progress value (typically between 0 and 1 where 0 is the beginning of the path, 0.5 is in the middle, and 1 is at the end)
 
autoRotate:Boolean (default = false) — When autoRotate is true, the target will automatically be rotated so that it is oriented to the angle of the path. To offset this value (like to always add 90 degrees for example), use the rotationOffset property.
 
rotationOffset:Number (default = 0) — When autoRotate is true, this value will always be added to the resulting rotation of the target.