/*______________________________________________________________ {History} Version Date People involved -------- ----- ----------------- MX v1.34 6th June 2002 Tatsuo Kato, Timothee Groleau, Robert Penner OO v2.0 29th Oct 2006 Gautam Gupta {Documentation} "dynTween" allows to apply motion tweens totally dynamically to movieclips. Usage Example: myMC.dynTween ( { duration: 40, _x: [400, "out", 30], _y: [200, "in"] } ); As seen there, the parameter(s) should be passed in a form of object(s). You can pass a series of objects as well. That will move "myMC" from the current position to (400,200) during 40 frames with easing effects, "out" with strength 30 for _x and "in" with strength 50 as a default for _y. There are 4 easing types; "in", "out", "inOut" and "outIn". "inOut" makes the tween accelerate in the first half and decelerate in the second half. "outIn" makes the tween decelerate in the first half and accelerate in the second half. Easing strength can take a value from 0 up to 100. If no strength is passed, it defaults to 50. And if no easing is needed at all, either of the following examples is fine. _x:[400] or _x:400 An example of the syntax with all the parameters used would look like: myMC.dynTween ({duration : 40, _x:[300, "outIn", 30], _y:100, _xscale:[200, "out"], _yscale:[-200, "inOut"], _rotation:[720, "outIn"], _alpha:30, myProp1:[15, "in"], myProp2:-47, callback : "_root.myFunc", cbArgs : {arg1 : 5, arg2 : "hello"} }, {duration : 10}, {duration : 20, _x : 30} ); callback is a function to pass, which you want the mc to execute when the tween is done. Its scope should be _root, that is, 'this' in the function body refers to _root. If the function which has called the dynTween method is passed as callback, the series of the tweens will loop until the reset method is called. cbArgs is an object of parameters to pass to the callback function. If there's only one parameter, it doesn't need to be an object; just passing a value will be fine. myProp1 and myProp2 in the example are user-defined variables of myMC. The values of them can tween too that way if necessary. You can simultaneously tween as many properties as you want, whether or not they are built-in, as long as their values are "number". And you can write a series of as many motion tweens as you want in a single action. They will be done one after another automatically. You can also make the caller MC just pause by passing no property arguments. myMC.dynTween ({duration : 10}); This makes myMC pause for duration of 10 frames. ______________________________________________________________*/ import Tween; dynamic class dynTweenClass extends MovieClip { var holder:Array; var tweenEngine:MovieClip; // constructor public function dynTweenClass() { }; // push all transitions to an array (holder) public function dynTween() { this.createEmptyMovieClip("tweenEngine", 20002); holder = new Array(); var i = arguments.length; while (i) { holder.push(new Tween(arguments[--i])); } begin(); } // execute each element in array (holder) private function begin() { var element = holder.pop(); element.setUp(this); run(element); } // run each effect at "onEnterFrame" interval private function run(dtObj) { var o = this; tweenEngine.cnt = 0; tweenEngine.onEnterFrame = function () { if (++this.cnt <= dtObj.dur) { for (var i in dtObj.props) { var p = dtObj.props[i]; o[i] = o.doEffect(p.ease, this.cnt, p.bgn, p.val, dtObj.dur, p.strength); } } else { if (o.holder.length) o.begin(); else delete o.tweenEngine; if (typeof(dtObj.callback) == "function") dtObj.callback.call(o, dtObj.cbArgs); else o[dtObj.callback](dtObj.cbArgs); } } } // compute each dynTween effect's values to modify the instance being 'dynTween'ed private function doEffect(effect, count, startVal, amount, interval, strength) { var num = 0; switch (effect) { case "none": num = startVal + amount * count / interval; break; case "in" : num = startVal+ amount*Math.pow((count/interval), strength); break; case "out" : num = startVal+ amount*(1 - Math.pow(1-count/interval, strength)); break; case "inOut": if (count <= (count/=2)) num = startVal+ amount/2 * Math.pow(count/interval, strength); else num = startVal+ amount - amount/2*Math.pow(2-count/interval, strength); break; case "outIn": if (count <= (count/=2)) num = startVal+ amount/2 * (1 - Math.pow(1-count/interval, strength)); else num = startVal+ amount/2 *(1 + Math.pow(count/interval-1, strength)); break; } return num; } }