/* class tweenManager for tweening prototypes version 1.1.7 Ladislav Zigo,lacoz@web.de */ class zigo.tweenManager{ private var tweenList:Array; private var tweenHolder:MovieClip; private var playing:Boolean; private var now:Number; private var ints:Array; private var lockedTweens:Object; private var updateIntId:Number; private var updateTime:Number; private var pausedTime:Number; private var isPaused:Boolean; public var broadcastEvents:Boolean; public var autoStop:Boolean; public var autoOverwrite:Boolean; function tweenManager(){ playing = false; isPaused = false; autoStop = false; broadcastEvents = false; autoOverwrite = true; ints = new Array(); lockedTweens = new Object(); tweenList = new Array(); } // function set updateInterval(time:Number):Void{ if (playing){ deinit() updateTime = time init() }else{ updateTime = time } } function get updateInterval():Number{ return updateTime; } // private methods private function init():Void{ if(updateTime > 0){ updateIntId = setInterval(this,"update",updateTime); }else{ // fix bug with "Simulate Download" // tweenHolder is still movieclip, but not on the stage if(tweenHolder._name == undefined){ // tweenHolder = _root.createEmptyMovieClip("_th_",6789); } var tm = this; tweenHolder.onEnterFrame = function(){ // this is faster because it eliminates usage of keyword "with" in update function tm.update.call(tm); } } playing = true; now = getTimer(); } private function deinit():Void{ playing = false; clearInterval(updateIntId); delete tweenHolder.onEnterFrame; } private function update():Void{ // loop all tween objects var t, i, j; i = tweenList.length; // broadcasting events if(broadcastEvents){ // list of updated mcs var ut, et; ut = {}; // list of ending mcs et = {}; } while (i--){ t = tweenList[i]; if(t.ts + t.d > now){ // compute value using equation function if(t.ctm == undefined){ // compute primitive value t.mc[t.pp] = t.ef(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(now-t.ts,t.stm[j],t.ctm[j],t.d,t.e1,t.e2) } t.c.setTransform(ttm); } if(broadcastEvents){ if(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(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; } } // last update call if(t.cb.updfunc != undefined){ t.cb.updfunc.apply(t.cb.updscope,t.cb.updargs); } // end tweens if (endt == undefined){ var endt = new Array(); } endt.push(i); } } // broadcast events (only 1 time for every mc) for (j in ut){ ut[j].broadcastMessage('onTweenUpdate'); } if(endt != undefined){ endTweens(endt); } for (j in et){ et[j].broadcastMessage('onTweenEnd'); } // update timer now = getTimer(); // updatedisplay if in setinterval mode if (updateTime > 0){ updateAfterEvent(); } } private function endTweens(tid_arr:Array):Void{ var cb_arr, tl, i, cb, j cb_arr = [] // splice tweens from tweenlist tl = tid_arr.length for (i = 0; i