/* ------------------------------------- DESCRIPTION: ------------------------------------- BezierTween class extends Macromedia's Tween class using Robert Penner's cubic bezier tween function ------------------------------------- USAGE: ------------------------------------- function BezierTween(obj, prop, begin, finish, duration, useSeconds, a_val, b_val); obj: reference - the object which the Tween targets prop: string - name of the property (in obj) that will be affected begin: number - the starting value of prop finish: number - the starting value of prop duration: number - the length of time of the motion useSeconds: boolean - a flag specifying whether to use seconds instead of frames a_val = control point A's value b_val = control point B's value ------------------------------------- EXAMPLE: ------------------------------------- //Create a new FLA. Copy this Class file into same folder as FLA. //Create a movieclip on stage with name "mcClip". //Put this code in frame 1. import mx.transitions.*; import mx.transitions.easing.*; twnBezX = new BezierTween(mcClip, "_x", 0, 300, 30, false, 100, 400); twnBezY = new BezierTween(mcClip, "_y", 0, 300, 30, false, 400, 100); twnBezX._tl = this; twnBezX.onMotionFinished = function(){ this._tl.tweenDone(); } function tweenDone(){ trace("tween done"); } ------------------------------------- CREDITS: ------------------------------------- BezierTween Class by Felix Turner (www.airtightinteractive.com) Bezier Tween function by Robert Penner (www.robertpenner.com) Tween Class by Macromedia */ import mx.transitions.BroadcasterMX; import mx.transitions.OnEnterFrameBeacon; import mx.transitions.Tween; class BezierTween extends Tween { public var point1:Number; public var point2:Number; ///////////////////////////////////////////////////////////////////////// /* constructor for BezierTween class obj: reference - the object which the Tween targets prop: string - name of the property (in obj) that will be affected begin: number - the starting value of prop duration: number - the length of time of the motion; set to infinity if negative or omitted useSeconds: boolean - a flag specifying whether to use seconds instead of frames */ function BezierTween (obj, prop, begin, finish, duration, useSeconds,point1,point2) { OnEnterFrameBeacon.init(); if (!arguments.length) return; this.obj = obj; this.prop = prop; this.begin = begin; this.position = begin; this.duration = duration; this.point1 = point1; this.point2 = point2; this.useSeconds = useSeconds; this.func = tweenCubicBez; this.finish = finish; this._listeners = []; this.addListener (this); this.start(); } function getPosition (t:Number):Number { if (t == undefined) t = this._time; return this.func (t, this.begin, this.change, this._duration,this.point1,this.point2); }; // Cubic Bezier tween from b to b+c, influenced by p1 & p2 // t: current time, b: beginning value, c: total change, d: duration // p1, p2: Bezier control point positions static function tweenCubicBez (t:Number, b:Number, c:Number, d:Number,p1:Number,p2:Number):Number { return ((t/=d)*t*c + 3*(1-t)*(t*(p2-b) + (1-t)*(p1-b)))*t + b; } }