home *** CD-ROM | disk | FTP | other *** search
/ Sears Catalog 2006 Spring/Summer (French Canadian) / SearsCanada-AutomneEte2006-FrenchVersion-WinMac.bin / fr / calendar / lmc_tween_as1.as < prev    next >
Text File  |  2005-07-27  |  17KB  |  658 lines

  1. /*
  2. Tweening prototypes for AS 1.0
  3. version 1.1.7
  4. Ladislav Zigo,lacoz@web.de
  5. */
  6. #include "easing_equations.as"
  7. //
  8. var Mp = MovieClip.prototype;
  9. //
  10. AsBroadcaster.initialize(Mp);
  11. Mp.$addListener = Mp.addListener;
  12. ASSetPropFlags(Mp, "$addListener", 1, 0);
  13. Mp.addListener = function(){
  14.     AsBroadcaster.initialize(this);
  15.     this.$addListener.apply(this,arguments);
  16. }
  17. //
  18. function tweenManager() {
  19.  this.playing = false
  20.  this.autoStop = false;
  21.  this.broadcastEvents = false; 
  22.  this.autoOverwrite = true; 
  23.  this.tweenList = new Array()
  24.  this.ints = new Array();
  25.  this.lockedTweens = new Object();
  26.  this.now = 0;
  27.  this.isPaused = false;
  28.  this.pausedTime = 0;
  29. }
  30. var tp = tweenManager.prototype;
  31. tp.setupdateInterval = function(time){
  32.     if (this.playing){
  33.         this.deinit()
  34.         this.updateTime = time
  35.         this.init()
  36.     }else{
  37.         this.updateTime = time
  38.     }
  39.  
  40. }
  41. tp.getupdateInterval = function(){
  42.     return this.updateTime;
  43. }
  44. tp.addProperty("updateInterval",tp.getupdateInterval, tp.setupdateInterval);
  45. //
  46. tp.init = function(){
  47.     var tm = this;    
  48.     if(tm.updateTime > 0){
  49.         tm.updateIntId = setInterval(tm,"update",tm.updateTime);
  50.     }else{
  51.         if(tm.tweenHolder._name == undefined){
  52.             tm.tweenHolder = _root.createEmptyMovieClip("_th_",6789); 
  53.         }
  54.         //tweenHolder.onEnterFrame = update
  55.     
  56.         tm.tweenHolder.onEnterFrame = function(){                
  57.             tm.update.call(tm);
  58.         }
  59.     }
  60.     tm.playing = true;
  61.     tm.now = getTimer();
  62. }
  63. //
  64. tp.deinit = function(){
  65.     this.playing = false;
  66.     clearInterval(this.updateIntId);
  67.     delete this.tweenHolder.onEnterFrame;
  68. }
  69. //-------------------------- private  methods
  70. tp.update = function() {
  71.     var i, t, j;
  72.     i = this.tweenList.length;
  73.     if(this.broadcastEvents){
  74.         // list of updated mcs
  75.         var ut = {};
  76.         // list of ending mcs
  77.         var et = {};
  78.     }
  79.     while (i--) {
  80.         t = this.tweenList[i];
  81.         if (t.ts+t.d>this.now) {
  82.             // compute value using equation function
  83.             if (t.ctm == undefined) {
  84.                 // compute primitive value
  85.                 t.mc[t.pp] = t.ef(this.now-t.ts, t.ps, t.ch, t.d, t.e1, t.e2);
  86.             } else {
  87.                 // compute color transform matrix 
  88.                 // stm is starting transform matrix, 
  89.                 // ctm is change in start & destination matrix 
  90.                 // ttm is computed (temporary) transform matrix
  91.                 // c is color object
  92.                 var ttm = {};
  93.                 for (j in t.ctm) {
  94.                     ttm[j] = t.ef(this.now-t.ts, t.stm[j], t.ctm[j], t.d, t.e1, t.e2);
  95.                 }
  96.                 t.c.setTransform(ttm);
  97.             }
  98.             if(this.broadcastEvents && ut[targetpath(t.mc)] == undefined){
  99.                 ut[targetpath(t.mc)] = t.mc;
  100.             }
  101.             if(t.cb.updfunc != undefined){
  102.                 t.cb.updfunc.apply(t.cb.updscope,t.cb.updargs);
  103.             }
  104.         } else {
  105.             // end , set up the property to end value;
  106.             if (t.ctm == undefined) {
  107.                 t.mc[t.pp] = t.ps+t.ch;
  108.             } else {
  109.                 var ttm = {};
  110.                 for (j in t.ctm) {
  111.                     ttm[j] = t.stm[j]+t.ctm[j];
  112.                 }
  113.                 t.c.setTransform(ttm);
  114.             }
  115.             if(this.broadcastEvents){
  116.                 if(ut[targetpath(t.mc)] == undefined){
  117.                     ut[targetpath(t.mc)] = t.mc;
  118.                 }
  119.                 
  120.                 if(et[targetpath(t.mc)] == undefined){
  121.                     et[targetpath(t.mc)] = t.mc;
  122.                 }
  123.             }
  124.             if(t.cb.updfunc != undefined){
  125.                 t.cb.updfunc.apply(t.cb.updscope,t.cb.updargs);
  126.             }
  127.             if (endt == undefined){
  128.                 var endt = new Array();
  129.             }
  130.             endt.push(i);
  131.         }
  132.     }
  133.     for (j in ut){
  134.         ut[j].broadcastMessage('onTweenUpdate');
  135.     }
  136.     if(endt != undefined){
  137.         this.endTweens(endt);
  138.     }
  139.     for (j in et){
  140.         et[j].broadcastMessage('onTweenEnd');
  141.     }
  142.     this.now = getTimer();
  143.     // update timer 
  144.     if (this.updateTime > 0){
  145.         updateAfterEvent();
  146.     }
  147.  
  148. };
  149. tp.endTweens = function(tid_arr){
  150. var cb_arr, tl, i, cb, j
  151. cb_arr = []
  152. // splice tweens from tweenlist 
  153. tl = tid_arr.length
  154. with(this){
  155.     for (i = 0; i<tl; i++){
  156.         cb = tweenList[tid_arr[i]].cb
  157.         if(cb != undefined){
  158.             var exec = true;
  159.             //do not add callbacks that are in cb_arr
  160.             for(j in cb_arr){
  161.                 if (cb_arr[j] ==  cb){
  162.                     exec = false;
  163.                     break;
  164.                 }
  165.             }
  166.             //
  167.             if(exec){
  168.                 cb_arr.push(cb)
  169.             }
  170.         }
  171.         tweenList.splice(tid_arr[i],1);
  172.     }
  173.     // execute callbacks
  174.     for (i = 0; i<cb_arr.length;i++){
  175.         cb_arr[i].func.apply(cb_arr[i].scope,cb_arr[i].args)
  176.     }
  177.     //
  178.     // /*1.1.6*/
  179.     if(tweenList.length==0){
  180.     // last tween removed, erase onenterframe function
  181.         deinit();
  182.     }
  183. }
  184. }
  185. // ------------- public methods
  186. tp.addTween = function(mc,props,pEnd,sec,eqFunc,callback,extra1,extra2){
  187.     var i, pp, addnew, j, t;
  188.     with(this){
  189.         //
  190.         if(!playing){
  191.             init();
  192.         }
  193.         for(i in props){
  194.             pp = props[i];
  195.             addnew = true;
  196.             //
  197.             if(pp.substr(0,4)!="_ct_"){
  198.                 // there is no color transform prefix, use primitive value tween
  199.                 //
  200.                 if(autoOverwrite){
  201.                     // find coliding tween and overwrite it 
  202.                     for (j in tweenList){
  203.                         t = tweenList[j];
  204.                         if(t.mc == mc && t.pp == pp){
  205.                             //
  206.                             t.ps = mc[pp];
  207.                             t.ch = pEnd[i] - mc[pp];
  208.                             t.ts = now;
  209.                             t.d = sec*1000;
  210.                             t.ef = eqFunc;
  211.                             t.cb = callback;
  212.                             t.e1 = extra1;
  213.                             t.e2 = extra2;
  214.                             addnew = false;                                                
  215.                             break;
  216.                         }
  217.                     }
  218.                 }
  219.                 if(addnew){    
  220.                 // not found add new
  221.                 tweenList.unshift({                            
  222.                           mc: mc,                
  223.                           pp: pp,                 
  224.                           ps: mc[pp],            
  225.                           ch: pEnd[i] - mc[pp], 
  226.                           ts: now,                 
  227.                           d:  sec * 1000,         
  228.                           ef: eqFunc,             
  229.                           cb: callback,            
  230.                           e1: extra1,            
  231.                           e2: extra2});            
  232.                 }
  233.             }else{
  234.                 // color trasform prefix found    
  235.                 // compute change matrix
  236.                 var c = new Color(mc);
  237.                 var stm = c.getTransform();
  238.                 // compute difference between starting and desionation matrix
  239.                 var ctm = {}
  240.                 for(j in pEnd[i]){
  241.                     // if is in destination matrix 
  242.                     if(pEnd[i][j] != stm[j] && pEnd[i][j] != undefined ){
  243.                         ctm[j] = pEnd[i][j] - stm[j];
  244.                     }
  245.                 }
  246.                 if(autoOverwrite){
  247.                 // find coliding tween and overwrite it 
  248.                 for (j in tweenList){
  249.                     t = tweenList[j];
  250.                     if(t.mc == mc && t.ctm != undefined){
  251.                             //
  252.                             t.c = c
  253.                             t.stm = stm    
  254.                             t.ctm =  ctm,
  255.                             t.ts = now;
  256.                             t.d = sec*1000;
  257.                             t.ef = eqFunc;
  258.                             t.cb = callback;
  259.                             t.e1 = extra1;
  260.                             t.e2 = extra2;
  261.                             addnew = false;                                                break;
  262.                         }
  263.                     }
  264.                 }
  265.                 if(addnew){    
  266.                 tweenList.unshift({
  267.                         mc:  mc,            //reference to movieclip
  268.                         c:   c,                //reference to movieclip color
  269.                         stm: stm,            //starting transform matrix
  270.                         ctm: ctm,            
  271.                         ts:  now,
  272.                         d:   sec * 1000,
  273.                         ef:  eqFunc,
  274.                         cb:  callback,
  275.                         e1:  extra1,
  276.                         e2:  extra2
  277.                     })
  278.                 }            
  279.                 
  280.             }
  281.         } // end for
  282.     if(broadcastEvents){
  283.         mc.broadcastMessage('onTweenStart');                 
  284.     }
  285.     if(callback.startfunc != undefined){
  286.         callback.startfunc.apply(callback.startscope,callback.startargs)
  287.     }
  288.     }// end with
  289. }
  290. tp.addTweenWithDelay = function(delay,mc,props,pEnd,sec,eqFunc,callback,extra1,extra2){
  291. with(this){
  292.     var il = ints.length;
  293.     var intid = setInterval(function(obj){
  294.         obj.addTween(mc, props, pEnd, sec, eqFunc, callback, extra1, extra2);
  295.         clearInterval(obj.ints[il].intid);
  296.         obj.ints[il] = undefined;
  297.     },delay*1000,this);
  298.     //
  299.     ints[il] = {mc: mc, props: props, pend:pEnd, intid:intid, st: this.now, delay:delay*1000, args: arguments.slice(1)}
  300. }
  301. }
  302. //
  303. tp.removeTween = function(mc,props){
  304. with (this){
  305.     var all, i, j
  306.     all = false;
  307.     if(props == undefined){
  308.         // props are undefined, remove all tweens
  309.         all = true;
  310.     }
  311.     i = tweenList.length; 
  312.     while (i--){
  313.         if(tweenList[i].mc == mc){
  314.             if(all){
  315.                 tweenList.splice(i,1);
  316.             }else{
  317.                 for(j in props){
  318.                     if(tweenList[i].pp == props[j] && tweenList[i].mc == mc){
  319.                         tweenList.splice(i,1);
  320.                         // (because allows add same properties for same mc,
  321.                         // all tweens must be checked) 
  322.                     } else if (props[j] == "_ct_" && tweenList[i].ctm != undefined && tweenList[i].mc == mc){
  323.                         // removing of colorTransform tweens
  324.                         tweenList.splice(i,1);
  325.                     }
  326.                 }
  327.             }
  328.         }
  329.     }
  330.     i = ints.length;
  331.     while(i-- && ints[i].mc == mc){
  332.         if(all){
  333.             // REMOVE ALL
  334.             clearInterval(ints[i].intid)
  335.             ints[i] = undefined
  336.         } else {
  337.             // REMOVE PROPERTIES
  338.             for(j