/* =============================================================================== Real hidden methods/functions ------------------------------------------------------------------------------- These functions are the real core of MC Tween. They control all tweenings, and are kept separated from the methods themselves for organization's sake. ------------------------------------------------------------------------------- */ _global.$createTweenController = function() { // INTERNAL USE: Creates the tween controller that will do all tween updates remotely var tweenHolder = _root.createEmptyMovieClip ("__tweenController__", 123432); // Any level tweenHolder.$_tweenPropList = new Array(); // Will hold the list of properties beeing tweened. an array of objects. tweenHolder.$_tTime = getTimer(); tweenHolder.onEnterFrame = _global.$updateTweens; }; ASSetPropFlags(_global, "$createTweenController", 1, 0); _global.$removeTweenController = function() { // INTERNAL USE: Destroys the tween controller in a centralized, clean, functional and paranoid way delete _root.__tweenController__.$_tweenPropList; delete _root.__tweenController__.$_tTime; delete _root.__tweenController__.onEnterFrame; _root.__tweenController__.removeMovieClip(); }; ASSetPropFlags(_global, "$removeTweenController", 1, 0); _global.$addTween = function(mtarget, prop, propDest, timeSeconds, animType, delay, callback, extra1, extra2, extras) { // INTERNAL USE: Adds a new tween for an object // Sets default values if undefined/invalid if (timeSeconds == undefined) timeSeconds = 0; // default time length if (animType == undefined || animType == "") animType = "easeOutExpo"; // default equation! if (delay == undefined) delay = 0; // default delay // Starts tweening.. prepares to create handling mcs // Faster this way if (typeof(prop) == "string") { // Single property var properties = [prop]; // Properties, as in "_x" var oldProperties = [mtarget[prop]]; // Old value, as in 0 var newProperties = [propDest]; // New (target) value, as in 100 } else { // Array of properties // ****Hm.. this looks strange... test concat() for speed? var properties = []; // Properties, as in "_x" var oldProperties = []; // Old value, as in 0 var newProperties = []; // New (target) value, as in 100 for (var i in prop) oldProperties.push (mtarget[prop[i]]); for (var i in prop) properties.push (prop[i]); for (var i in propDest) newProperties.push (propDest[i]); } var $_callback_assigned = false; // 1.7.4: Knows if callback has already been assigned to an object // Checks if the master movieClip (which controls all tweens) exists, if not creates it if (_root.__tweenController__ == undefined) _global.$createTweenController(); var tweenPropList = _root.__tweenController__.$_tweenPropList; // Now set its data (adds to the list of properties being tweened) var tTime = _root.__tweenController__.$_tTime; // 2.16.12: laco's suggestion, for a REAL uniform time for (var i in oldProperties) { // Set one new object for each property that should be tweened if (newProperties[i] != undefined && !mtarget.$_isTweenLocked) { // Only creates tweenings for properties that are not undefined. That way, // certain properties can be optional on the shortcut functions even though // they are passed to the tweening function - they're just ignored // Checks if it's at the tween list already if (mtarget.$_tweenCount > 0) { for (var pti=0; pti 0 ? mtarget.$_tweenCount+1 : 1; // to avoid setting ++ to undefined $_callback_assigned = true; // 1.7.4 } } // Hides stuff from public view on the movieclip being tweened ASSetPropFlags(mtarget, "$_tweenCount", 1, 0); // List of stuff being tweened }; ASSetPropFlags(_global, "$addTween", 1, 0); _global.$updateTweens = function() { // INTERNAL USE: This is ran every frame to update *all* existing tweens // On each pass, it should check and update the properties var tTime = this.$_tTime = getTimer(); for (var i=0; i.stopTween ("_x"); // Stops _x tweening // .stopTween (["_x", "_y"]); // Stops _x and _y tweening // .stopTween ("_x", "_y"); // Stops _x and _y tweening // .stopTween (); // Stops all tweening processes if (typeof (props) == "string") props = [props]; // in case of one property, turn into array if (props != undefined) { // 2.22.26: counts all arguments as parameters too for (var i=1; i 0 ? true : false); }; ASSetPropFlags(MovieClip.prototype, "isTweening", 1, 0); ASSetPropFlags(TextField.prototype, "isTweening", 1, 0); /* =============================================================================== Shortcut methods/functions ------------------------------------------------------------------------------- Start tweenings with different commands. These methods are used mostly for code readability and special handling of some non-property attributes (like movieclip color, sound volume, etc) but also to make the coding easier for non-expert programmers or designers. ------------------------------------------------------------------------------- */ MovieClip.prototype.alphaTo = TextField.prototype.alphaTo = function (propDest_a, timeSeconds, animType, delay, callback, extra1, extra2) { // Does an alpha tween. Example: .alphaTo(100) _global.$addTween(this, "_alpha", propDest_a, timeSeconds, animType, delay, callback, extra1, extra2); }; ASSetPropFlags(MovieClip.prototype, "alphaTo", 1, 0); ASSetPropFlags(TextField.prototype, "alphaTo", 1, 0); MovieClip.prototype.rotateTo = TextField.prototype.rotateTo = function (propDest_rotation, timeSeconds, animType, delay, callback, extra1, extra2) { // Rotates an object given a degree. _global.$addTween(this, "_rotation", propDest_rotation, timeSeconds, animType, delay, callback, extra1, extra2); }; ASSetPropFlags(MovieClip.prototype, "rotateTo", 1, 0); ASSetPropFlags(TextField.prototype, "rotateTo", 1, 0); MovieClip.prototype.scaleTo = TextField.prototype.scaleTo = function (propDest_scale, timeSeconds, animType, delay, callback, extra1, extra2) { // Scales an object uniformly. _global.$addTween(this, ["_xscale", "_yscale"], [propDest_scale, propDest_scale], timeSeconds, animType, delay, callback, extra1, extra2); }; ASSetPropFlags(MovieClip.prototype, "scaleTo", 1, 0); ASSetPropFlags(TextField.prototype, "scaleTo", 1, 0); MovieClip.prototype.slideTo = TextField.prototype.slideTo = function (propDest_x, propDest_y, timeSeconds, animType, delay, callback, extra1, extra2) { // Does a xy sliding tween. Example: .slideTo(100, 100) _global.$addTween(this, ["_x", "_y"], [propDest_x, propDest_y], timeSeconds, animType, delay, callback, extra1, extra2); }; ASSetPropFlags(MovieClip.prototype, "slideTo", 1, 0); ASSetPropFlags(TextField.prototype, "slideTo", 1, 0); MovieClip.prototype.blurTo = TextField.prototype.blurTo = function () { // Creates a blur on the object. // 1 -> (propDest_blur, quality, timeSeconds, animType, delay, callback, extra1, extra2) // 2 -> (BlurFilter, timeSeconds, animType, delay, callback, extra1, extra2) // propDest_blur = blur, as on flash.filters.BlurFilter .blurX and .blurY parameters // quality = blur quality, as on flash.filters.BlurFilter .quality if (typeof(arguments[0]) == "object" && arguments[0] != undefined) { // It's an object _global.$addTween(this, ["__special_blur_x__","__special_blur_y__"], [arguments[0].blurX, arguments[0].blurY], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], {__special_blur_quality__:arguments[0].quality}); } else { // Normal parameters _global.$addTween(this, ["__special_blur_x__","__special_blur_y__"], [arguments[0], arguments[0]], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], {__special_blur_quality__:arguments[1]}); } }; ASSetPropFlags(MovieClip.prototype, "blurTo", 1, 0); ASSetPropFlags(TextField.prototype, "blurTo", 1, 0); _global.findTweenValue = function (_propStart, _propDest, _timeStart, _timeNow, _timeDest, _animType, _extra1, _extra2) { // Returns the current value of a property mid-value given the time. // Used by the tween methods to see where the movieclip should be on the current // tweening process. All equations on this function are Robert Penner's work. var t = _timeNow - _timeStart; // current time (frames, seconds) var b = _propStart; // beginning value var c = _propDest - _propStart; // change in value var d = _timeDest - _timeStart; // duration (frames, seconds) var a = _extra1; // amplitude (optional - used only on *elastic easing) var p = _extra2; // period (optional - used only on *elastic easing) var s = _extra1; // overshoot ammount (optional - used only on *back easing) switch (_animType.toLowerCase()) { case "linear": // simple linear tweening - no easing return c*t/d + b; case "easeinexpo": // exponential (2^t) easing in - accelerating from zero velocity return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; case "easeoutexpo": // exponential (2^t) easing out - decelerating to zero velocity return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; case "easeinelastic": // elastic (exponentially decaying sine wave) easing in if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; if (!a || a < Math.abs(c)) { a=c; var s=p/4; } else var s = p/(2*Math.PI) * Math.asin (c/a); return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; case "easeoutelastic": // elastic (exponentially decaying sine wave) easing out if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; if (!a || a < Math.abs(c)) { a=c; var s=p/4; } else var s = p/(2*Math.PI) * Math.asin (c/a); return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b); // Robert Penner's explanation for the s parameter (overshoot ammount): // s controls the amount of overshoot: higher s means greater overshoot // s has a default value of 1.70158, which produces an overshoot of 10 percent // s==0 produces cubic easing with no overshoot case "easeinback": // back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in - backtracking slightly, then reversing direction and moving to target if (s == undefined) s = 1.70158; return c*(t/=d)*t*((s+1)*t - s) + b; case "easeoutback": // back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out - moving towards target, overshooting it slightly, then reversing and coming back to target if (s == undefined) s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; // This were changed a bit by me (since I'm not using Penner's own Math.* functions) // So I changed it to call findTweenValue() instead (with some different arguments) case "easeinbounce": // bounce (exponentially decaying parabolic bounce) easing in return c - findTweenValue (0, c, 0, d-t, d, "easeOutBounce") + b; case "easeoutbounce": // bounce (exponentially decaying parabolic bounce) easing out if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b; } else if (t < (2/2.75)) { return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; } else if (t < (2.5/2.75)) { return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; } else { return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; } default: trace ("MC TWEEN ### Error on transition: there's no \""+_animType+"\" animation type."); return 0; } }; ASSetPropFlags(_global, "findTweenValue", 1, 0);