API Documentation | All Packages | All Classes | Index | Frames No Frames |
Class PathFollower

Package | com.greensock.motionPaths
Class | public class PathFollower

A PathFollower is used to associate a particular target object (like a MovieClip, Point, Sprite, etc.) with a MotionPath and it offers a tweenable `progress` property that manages positioning the target on the path accordingly. The `progress` property is a value between 0 and 1 where 0 is at the beginning of the path, 0.5 is in the middle, and 1 is at the end. When the follower's `autoRotate` property is `true`, the target will be rotated in relation to the path that it is following.

Example
Example AS3 code:

    import com.greensock.*;
    import com.greensock.motionPaths.*;

    //create a circle motion path at coordinates x:150, y:150 with a radius of 100
    var circle:Circle2D = new Circle2D(150, 150, 100);

    //make the MovieClip "mc" follow the circle and start at a position of 90 degrees (this returns a PathFollower instance)
    var follower:PathFollower = circle.addFollower(mc, circle.angleToProgress(90), true);

    //tween the follower clockwise along the path to 315 degrees
    TweenLite.to(follower, 2, {progress:circle.followerTween(follower, 315, Direction.CLOCKWISE)});

    //tween the follower counter-clockwise to 200 degrees and add an extra revolution
    TweenLite.to(follower, 2, {progress:circle.followerTween(follower, 200, Direction.COUNTER_CLOCKWISE, 1)});

NOTES

- All followers are automatically updated when you alter the MotionPath that they're following.
- To tween all followers along the path at once, simply tween the MotionPath's `progress` property which will provide better performance than tweening each follower independently.

Copyright 2011, 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

| Property | Defined by
--- | --- | ---
|  | autoRotate : Boolean When `autoRotate` is `true`, the follower will automatically be rotated so that it is oriented to the angle of the path that it is following. | PathFollower
|  | path : MotionPath The MotionPath instance that this PathFollower should follow | PathFollower
|  | progress : Number A value between 0 and 1 that indicates the follower's position along the motion path. | PathFollower
|  | rawProgress : Number Identical to `progress` except that the value doesn't get re-interpolated between 0 and 1. | PathFollower
|  | rotationOffset : Number When `autoRotate` is `true`, this value will always be added to the resulting `rotation` of the target. | PathFollower
|  | target : Object The target object associated with the PathFollower (like a Sprite, MovieClip, Point, etc.). | PathFollower

Public Methods

| Method | Defined by
--- | --- | ---
|  | PathFollower(target:Object, autoRotate:Boolean = false, rotationOffset:Number = 0) Constructor | PathFollower

Property detail

autoRotate | property

`public var autoRotate:Boolean`

When `autoRotate` is `true`, the follower will automatically be rotated so that it is oriented to the angle of the path that it is following. To offset this value (like to always add 90 degrees for example), use the `rotationOffset` property.

path | property |

`public var path:MotionPath`

The MotionPath instance that this PathFollower should follow

progress | property |

`progress:Number` [read-write]

A value between 0 and 1 that indicates the follower's position along the motion path. For example, to place the object on the path at the halfway point, you would set its `progress` to 0.5. You can tween to values that are greater than 1 or less than 0 but the values are simply wrapped. So, for example, setting `progress` to 1.2 is the same as setting it to 0.2 and -0.2 is the same as 0.8. If your goal is to tween the PathFollower around a Circle2D twice completely, you could just add 2 to the `progress` value or use a relative value in the tween, like:
`TweenLite.to(myFollower, 5, {progress:"2"}); //or myFollower.progress + 2`
`progress` is identical to `rawProgress` except that `rawProgress` does not get re-interpolated between 0 and 1. For example, if `rawProgress` is set to -3.4, `progress` would be 0.6. `rawProgress` can be useful if you need to find out how many times the PathFollower has wrapped. Also note that if you set `progress` to any value outside of the 0-1 range, `rawProgress` will be set to that exact value. If `progress` is set to a value within the typical 0-1 range, it will only affect the decimal value of `rawProgress`. For example, if `rawProgress` is 3.4 and then you set `progress` to 0.1, `rawProgress` will end up at 3.1 (notice the "3" integer was kept). But if `progress` was instead set to 5.1, since it exceeds the 0-1 range, `rawProgress` would become 5.1. This behavior was adopted in order to deal most effectively with wrapping situations. For example, if `rawProgress` was tweened to 3.4 and then later you wanted to fine-tune where things were positioned by tweening `progress` to 0.8, it still may be important to be able to determine how many loops/wraps occurred, so `rawProgress` should be 3.8, not reset to 0.8. Feel free to use `rawProgress` exclusively if you prefer to avoid any of the re-interpolation that occurs with `progress`.

Implementation
`public function get progress():Number`
`public function set progress(value:Number):void`

See also

rawProgress

rawProgress | property |

`rawProgress:Number` [read-write]

Identical to `progress` except that the value doesn't get re-interpolated between 0 and 1. `rawProgress` (and `progress`) indicates the follower's position along the motion path. For example, to place the object on the path at the halfway point, you could set its `rawProgress` to 0.5. You can tween to values that are greater than 1 or less than 0. For example, setting `rawProgress` to 1.2 also sets `progress` to 0.2 and setting `rawProgress` to -0.2 is the same as setting `progress` to 0.8. If your goal is to tween the PathFollower around a Circle2D twice completely, you could just add 2 to the `rawProgress` value or use a relative value in the tween, like:
`TweenLite.to(myFollower, 5, {rawProgress:"2"}); //or myFollower.rawProgress + 2`
Since `rawProgress` doesn't re-interpolate values to always fitting between 0 and 1, it can be useful if you need to find out how many times the PathFollower has wrapped.

Implementation
`public function get rawProgress():Number`
`public function set rawProgress(value:Number):void`

See also

progress

rotationOffset | property |

`public var rotationOffset:Number`

When `autoRotate` is `true`, this value will always be added to the resulting `rotation` of the target.

target | property |

`public var target:Object`

The target object associated with the PathFollower (like a Sprite, MovieClip, Point, etc.). The object must have x and y properties.

Constructor detail

PathFollower | () | constructor

`public function PathFollower(target:Object, autoRotate:Boolean = false, rotationOffset:Number = 0)`

Constructor

Parameters

| `target:Object` — The target object associated with the PathFollower (like a Sprite, MovieClip, Point, etc.). The object must have x and y properties.
| `autoRotate:Boolean` (default = `false`)`` — When `autoRotate` is `true`, the follower will automatically be rotated so that it is oriented to the angle of the path that it is following. 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.