In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Tweening Along a Graph with TweenLite

There is of course better ways to do this.  Like putting the getter/setter dierctly on the 
DisplayObject instead of having a control class like this.  But, this was kind of a fun way to
go about it I thought.
Get Adobe Flash player
by PESakaTFM 13 Jan 2011
/**
There is of course better ways to do this.  Like putting the getter/setter dierctly on the 
DisplayObject instead of having a control class like this.  But, this was kind of a fun way to
go about it I thought.
**/
package
{
    import flash.display.Sprite;
    
    import gs.TweenLite;
    import gs.easing.Expo;
    
    [SWF(width=400, height=400, backgroundColor="#000000")]
    public class MotionTest extends Sprite
    {
        public var dot:Sprite;
        public var motion:CircularMotion;
        
        public function MotionTest()
        {
            dot = new Sprite();
            dot.graphics.beginFill(0xFF0000, 1);
            dot.graphics.drawCircle(0,0,10);
            dot.x = 200;
            dot.y = 200;
            
            this.addChild(dot);
            
            motion = new CircularMotion(dot, 150);
            
            forward();
        }
        
        public function forward():void
        {
            TweenLite.to(motion, 4, {radians:2*Math.PI, ease:Expo.easeInOut, onComplete:reverse});
        }
        
        public function reverse():void
        {
            TweenLite.to(motion, 4, {degrees:0, ease:Expo.easeInOut, onComplete:forward});
        }
    }
}
    import flash.display.DisplayObject;
    

class CircularMotion
{
    protected var _obj:DisplayObject;
    protected var angle:Number = 0;  // in radians
    protected var r:Number = 0;
    public var x:Number = 0;
    public var y:Number = 0;
    
    public function CircularMotion(obj:DisplayObject, radius:Number)
    {
        _obj = obj;
        r = radius;
        x = _obj.x;
        y = _obj.y;
        
        radians = 0;
    }
    
    public function get degrees():Number { return ((angle/Math.PI)*180); }
    public function set degrees(val:Number):void
    {
        radians = (val/180)*Math.PI;
    }
    
    public function get radians():Number { return angle; }
    public function set radians(val:Number):void
    {
        angle = val;
        _obj.x = x + Math.cos(angle)*r;
        _obj.y = y + Math.sin(angle)*r;
    }
}