/* Tweening prototypes for AS 1.0 version 1.1.7 Ladislav Zigo,lacoz@web.de */ #include "easing_equations.as" // var Mp = MovieClip.prototype; // AsBroadcaster.initialize(Mp); Mp.$addListener = Mp.addListener; ASSetPropFlags(Mp, "$addListener", 1, 0); Mp.addListener = function(){ AsBroadcaster.initialize(this); this.$addListener.apply(this,arguments); } // function tweenManager() { this.playing = false this.autoStop = false; this.broadcastEvents = false; this.autoOverwrite = true; this.tweenList = new Array() this.ints = new Array(); this.lockedTweens = new Object(); this.now = 0; this.isPaused = false; this.pausedTime = 0; } var tp = tweenManager.prototype; tp.setupdateInterval = function(time){ if (this.playing){ this.deinit() this.updateTime = time this.init() }else{ this.updateTime = time } } tp.getupdateInterval = function(){ return this.updateTime; } tp.addProperty("updateInterval",tp.getupdateInterval, tp.setupdateInterval); // tp.init = function(){ var tm = this; if(tm.updateTime > 0){ tm.updateIntId = setInterval(tm,"update",tm.updateTime); }else{ if(tm.tweenHolder._name == undefined){ tm.tweenHolder = _root.createEmptyMovieClip("_th_",6789); } //tweenHolder.onEnterFrame = update tm.tweenHolder.onEnterFrame = function(){ tm.update.call(tm); } } tm.playing = true; tm.now = getTimer(); } // tp.deinit = function(){ this.playing = false; clearInterval(this.updateIntId); delete this.tweenHolder.onEnterFrame; } //-------------------------- private methods tp.update = function() { var i, t, j; i = this.tweenList.length; if(this.broadcastEvents){ // list of updated mcs var ut = {}; // list of ending mcs var et = {}; } while (i--) { t = this.tweenList[i]; if (t.ts+t.d>this.now) { // compute value using equation function if (t.ctm == undefined) { // compute primitive value t.mc[t.pp] = t.ef(this.now-t.ts, t.ps, t.ch, t.d, t.e1, t.e2); } else { // compute color transform matrix // stm is starting transform matrix, // ctm is change in start & destination matrix // ttm is computed (temporary) transform matrix // c is color object var ttm = {}; for (j in t.ctm) { ttm[j] = t.ef(this.now-t.ts, t.stm[j], t.ctm[j], t.d, t.e1, t.e2); } t.c.setTransform(ttm); } if(this.broadcastEvents && ut[targetpath(t.mc)] == undefined){ ut[targetpath(t.mc)] = t.mc; } if(t.cb.updfunc != undefined){ t.cb.updfunc.apply(t.cb.updscope,t.cb.updargs); } } else { // end , set up the property to end value; if (t.ctm == undefined) { t.mc[t.pp] = t.ps+t.ch; } else { var ttm = {}; for (j in t.ctm) { ttm[j] = t.stm[j]+t.ctm[j]; } t.c.setTransform(ttm); } if(this.broadcastEvents){ if(ut[targetpath(t.mc)] == undefined){ ut[targetpath(t.mc)] = t.mc; } if(et[targetpath(t.mc)] == undefined){ et[targetpath(t.mc)] = t.mc; } } if(t.cb.updfunc != undefined){ t.cb.updfunc.apply(t.cb.updscope,t.cb.updargs); } if (endt == undefined){ var endt = new Array(); } endt.push(i); } } for (j in ut){ ut[j].broadcastMessage('onTweenUpdate'); } if(endt != undefined){ this.endTweens(endt); } for (j in et){ et[j].broadcastMessage('onTweenEnd'); } this.now = getTimer(); // update timer if (this.updateTime > 0){ updateAfterEvent(); } }; tp.endTweens = function(tid_arr){ var cb_arr, tl, i, cb, j cb_arr = [] // splice tweens from tweenlist tl = tid_arr.length with(this){ for (i = 0; i 0){ $tweenManager.addTweenWithDelay(delay,this, props, pEnd, seconds, eqf, callback, extra1, extra2); }else{ $tweenManager.addTween(this, props, pEnd, seconds, eqf, callback, extra1, extra2); } }; ASSetPropFlags(Mp, "tween", 1, 0); Mp.stopTween = function(props) { if (typeof (props) == "string") { props = [props]; } $tweenManager.removeTween(this, props); }; ASSetPropFlags(Mp, "stopTween", 1, 0); Mp.isTweening = function() { //returns boolean return $tweenManager.isTweening(this); }; ASSetPropFlags(Mp, "isTweening", 1, 0); Mp.getTweens = function() { // returns count of running tweens return $tweenManager.getTweens(this); }; ASSetPropFlags(Mp, "getTweens", 1, 0); Mp.lockTween = function() { $tweenManager.lockTween(this,true); }; ASSetPropFlags(Mp, "lockTween", 1, 0); Mp.unlockTween = function() { $tweenManager.lockTween(this,false); }; ASSetPropFlags(Mp, "unlockTween", 1, 0); Mp.isTweenLocked = function() { return $tweenManager.isTweenLocked(this); }; ASSetPropFlags(Mp, "isTweenLocked", 1, 0); // == shortcut methods == // these methods only passes parameters to tween method Mp.alphaTo = function (destAlpha, seconds, animType, delay, callback, extra1, extra2) { this.tween(["_alpha"],[destAlpha],seconds,animType,delay,callback,extra1,extra2) } ASSetPropFlags(Mp, "alphaTo", 1, 0); Mp.brightnessTo = function (bright, seconds, animType, delay, callback, extra1, extra2) { // destionation color transform matrix var percent = 100 - Math.abs(bright); var offset = 0; if (bright > 0) offset = 256 * (bright / 100); var destCt = {ra: percent, rb:offset, ga: percent, gb:offset, ba: percent,bb:offset} // this.tween(["_ct_"],[destCt],seconds,animType,delay,callback,extra1,extra2) } ASSetPropFlags(Mp, "brightnessTo", 1, 0); Mp.colorTo = function (destColor, seconds, animType, delay, callback, extra1, extra2) { // destionation color transform matrix var destCt = {rb: destColor >> 16, ra:0, gb: (destColor & 0x00FF00) >> 8, ga:0, bb: destColor & 0x0000FF,ba:0} // this.tween(["_ct_"],[destCt],seconds,animType,delay,callback,extra1,extra2) } ASSetPropFlags(Mp, "colorTo", 1, 0); Mp.colorTransformTo = function (ra, rb, ga, gb, ba, bb, aa, ab, seconds, animType, delay, callback, extra1, extra2) { // destionation color transform matrix var destCt = {ra: ra ,rb: rb , ga: ga, gb: gb, ba: ba, bb: bb, aa: aa, ab: ab} // this.tween(["_ct_"],[destCt],seconds,animType,delay,callback,extra1,extra2) } ASSetPropFlags(Mp, "colorTransformTo", 1, 0); Mp.scaleTo = function (destScale, seconds, animType, delay, callback, extra1, extra2) { this.tween(["_xscale", "_yscale"],[destScale, destScale],seconds,animType,delay,callback,extra1,extra2) } ASSetPropFlags(Mp, "scaleTo", 1, 0); Mp.slideTo = function (destX, destY, seconds, animType, delay, callback, extra1, extra2) { this.tween(["_x", "_y"],[destX, destY],seconds,animType,delay,callback,extra1,extra2) } ASSetPropFlags(Mp, "slideTo", 1, 0); Mp.rotateTo = function (destRotation, seconds, animType, delay, callback, extra1, extra2) { this.tween(["_rotation"],[destRotation],seconds,animType,delay,callback,extra1,extra2) } ASSetPropFlags(Mp, "rotateTo", 1, 0); // Mp.getFrame = function() { return this._currentframe; }; ASSetPropFlags(Mp, "getFrame", 1, 0); Mp.setFrame = function(fr) { this.gotoAndStop(Math.round(fr)); }; ASSetPropFlags(Mp, "setFrame", 1, 0); Mp.addProperty("_frame", Mp.getFrame, Mp.setFrame); ASSetPropFlags(Mp, "_frame", 1, 0); // Mp.frameTo = function(endframe, duration, animType, delay, callback, extra1, extra2) { if (endframe == undefined) { endframe = this._totalframes; } this.tween("_frame", endframe, duration, animType, delay, callback, extra1, extra2); }; ASSetPropFlags(Mp, "frameTo", 1, 0); Mp.brightOffsetTo = function(percent, seconds, animType, delay, callback, extra1, extra2) { var offset = 256*(percent/100); var destCt = {ra:100, rb:offset, ga:100, gb:offset, ba:100, bb:offset}; this.tween(["_ct_"], [destCt], seconds, animType, delay, callback, extra1, extra2); }; ASSetPropFlags(Mp, "brightOffsetTo", 1, 0); Mp.contrastTo = function(percent, seconds, animType, delay, callback, extra1, extra2) { // from Robert Penner color toolkit var t = {}; t.ra = t.ga=t.ba=percent; t.rb = t.gb=t.bb=128-(128/100*percent); this.tween(["_ct_"], [t], seconds, animType, delay, callback, extra1, extra2); }; ASSetPropFlags(Mp, "contrastTo", 1, 0); // delete Mp;