FuseItem.as

Go to the documentation of this file.
00001 import com.mosesSupposes.fuse.FuseKitCommon;
00002 
00020 class com.mosesSupposes.fuse.FuseItem
00021 {
00026         public static var registryKey:String = 'fuseItem';
00027         
00031         public static var ADD_UNDERSCORES:Boolean = true; 
00032         
00038         public var _nItemID:Number;
00039         
00044         private static var _ZigoEngine:Object;
00045         
00050         private var _initObj:Object;
00051         
00056         private var _nFuseID:Number;
00057         
00062         public var _nPlaying:Number = -1;
00063         
00068         private var _bStartSet:Boolean = false;
00069         
00074         private var _bTrigger:Boolean = false;
00075         
00080         private var _aTweens:Array;
00081         
00086         private var _oElements:Object;
00087         
00092         private var _aProfiles:Array;
00093         
00098         private var _sImage:String;
00099         
00104         private var _oTemps:Object;
00105         
00110         private static var _aInstances:Array;
00111         
00116         public static function doTween():String
00117         {
00118                 for (var i:String in arguments) {
00119                         if (typeof arguments[i]=='object') {
00120                                 if (_aInstances==undefined) _aInstances = new Array();
00121                                 var o:FuseItem = new FuseItem(_aInstances.length, arguments[i], -1);
00122                                 return o.startItem();
00123                         }
00124                 }
00125         }
00126 
00127         // --------------------------------------------------------------------//
00128         //      1. Fuse-access methods
00129         //      2. Constructor & parseProfile
00130         //      3. doTweens, tween event handlers, utils 
00131         // --------------------------------------------------------------------//
00132         
00133         // 1.
00134         
00140         public function getLabel():String
00141         {
00142                 return _oElements.label;
00143         }
00144         
00150         public function hasTriggerFired():Boolean
00151         {
00152                 return (_bTrigger==true);
00153         }
00154         
00155         
00161         public function getInitObj():Object
00162         {
00163                 return (_initObj);
00164         }
00165         
00171         public function getActiveTargets(targetList:Array):Array
00172         {
00173                 if (!(_aTweens.length>0)) return targetList;
00174                 var found:Boolean = false;
00175                 for (var i:String in _aTweens) {
00176                         // filter duplicates
00177                         for (var j:String in targetList) { 
00178                                 if (targetList[j]==(_aTweens[i]).targ) {
00179                                         found = true;
00180                                         break;
00181                                 }
00182                         }
00183                         if (found==false) {
00184                                 targetList.unshift((_aTweens[i]).targ);
00185                         }
00186                 }
00187                 return targetList;
00188         }
00189         
00193         public function toString():String { return String((_sID())+':'+_sImage); }
00194         
00201         public function evalDelay(scope:Object):Number 
00202         {
00203                 var d:Object = _oElements.delay;
00204                 if (d instanceof Function) {
00205                         d = d.apply((_oElements.delayscope!=undefined) ? _oElements.delayscope : scope);
00206                 }
00207                 if (typeof d=='string') d = (parseClock(String(d)));
00208                 if (_global.isNaN(Number(d))==true) return 0;
00209                 return Number(d);
00210         }
00211         
00219         public function startItem(targs:Array, scope:Object):String
00220         {
00221                 _ZigoEngine = _global.com.mosesSupposes.fuse.ZigoEngine;
00222                 var fuse:Object = _global.com.mosesSupposes.fuse.Fuse;
00223                 var outputLevel:Number = (fuse!=undefined) ? fuse.OUTPUT_LEVEL : _ZigoEngine.OUTPUT_LEVEL;
00224                 // Fuse command like 'pause' or 'stop'. v2.0: Only delay,scope,args are retained for items containing command.
00225                 if (_oElements.command!=null) { 
00226                         var validCommands:String = '|start|stop|pause|resume|skipTo|setStartProps|';
00227                         var cs:Object = (_oElements.scope || scope); // profile scope used for eval only. command always sent to parent fuse
00228                         var command:String = (_oElements.command instanceof Function) ? String(_oElements.command.apply(cs)) : String(_oElements.command); // user can pass a Delegate to scope this
00229                         // IMPORTANT: args param is not used during eval, args are passed to Fuse, primarily for use with skipTo(index/label)
00230                         var args:Array = (_oElements.args instanceof Function) ? _oElements.args.apply(cs) : _oElements.args;
00231                         if (validCommands.indexOf('|'+command+'|')==-1 || (command=='skipTo' && args==undefined)) {
00232                                 if (outputLevel>0) FuseKitCommon.error('111', command);
00233                         }
00234                         else {
00235                                 _nPlaying = 1;
00236                                 if (!(args instanceof Array)) args = (args==null) ? [] : [args];
00237                                 dispatchRequest(String(command), args);
00238                         }
00239                         return null;
00240                 }
00241                 // Changed order to deal with skipLevel. Now we tween first then fire callbacks and events.
00242                 if (_aTweens.length>0) this.stop();
00243                 _ZigoEngine.addListener(this); // For monitoring targets that go missing. Only one corresponding remove, in stop(), which is called by complete().
00244                 _nPlaying = 2; // Special flag meaning doTweens is running, important for avoiding onTweenInterrupt/End conflicts.
00245                 var propsAdded:String = null;
00246                 if (_aProfiles.length>0) {
00247                         if (_ZigoEngine==undefined) {
00248                                 FuseKitCommon.error('112');
00249                         }
00250                         else {
00251                                 propsAdded = doTweens(targs, scope, false);
00252                         }
00253                 }
00254                 // do not move. Callbacks can contain pause or other play commands, so this is checked afterward
00255                 _nPlaying = 1; 
00256                 
00257                 // Non-tween callbacks & events (skipped if skipLevel is 2 and all tweens failed)
00258                 var fa:Array = _oElements.aEvents;
00259                 for (var i:String in fa) {
00260                         if (propsAdded==null && _aTweens.length>0 && (fa[i]).skipLevel==2) continue;
00261                         fireEvents(fa[i],scope,outputLevel);
00262                 }
00263                 if (propsAdded==null && !(_aTweens.length>0) && _nPlaying==1) {
00264                         if (outputLevel==3) FuseKitCommon.output('-'+(_sID())+' no tweens added - item done. [getTimer()='+getTimer()+']');
00265                         complete();
00266                 }
00267                 return propsAdded;
00268         }
00269         
00274         public function stop():Void
00275         {
00276                 // (for onTweenInterrupt)
00277                 var doOnStop:Boolean = (_nPlaying>-1); 
00278                 _nPlaying = -1;
00279                 // active stop: clear this item's tweens and remove listeners
00280                 if (doOnStop==true) onStop();
00281                 _ZigoEngine.removeListener(this);
00282         }
00283         
00284         // -- private --
00285         
00289         private static function removeInstance(id:Number):Void
00290         {
00291                 FuseItem(_aInstances[id]).destroy();
00292                 delete _aInstances[id];
00293         }
00294 
00295         
00300         private function onStop():Void 
00301         {
00302                 _bStartSet = false;
00303                 for (var i:String in _aTweens) {
00304                         var to:Object = _aTweens[i];
00305                         to.targ.removeListener(this);
00306                         _ZigoEngine.removeTween(to.targ, to.props);
00307                         delete _aTweens[i];
00308                 }
00309                 delete _aTweens;
00310                 _bTrigger = false;
00311         }
00312         
00318         private function evtSetStart(o:Object):Void
00319         {
00320                 // no starts to set or Fuse is about to play this item.
00321                 if (_sImage.indexOf('StartProps:')==-1 || o.curIndex==_nItemID) {
00322                         return;
00323                 }
00324                 if (o.all!=true) {
00325                         var match:Boolean = false;
00326                         for (var i:String in o.filter) {
00327                                 if (Number(o.filter[i])==_nItemID || String(o.filter[i])==_oElements.label) match = true;
00328                         }
00329                         if (match==false) {
00330                                 return;
00331                         }
00332                 }
00333                 doTweens(o.targs, o.scope, true);
00334                 // flag removed when parent Fuse stopped.
00335                 _bStartSet = true;
00336         }
00337 
00338         
00344         public function pause(resume:Boolean):Void
00345         {
00346                 if (_nPlaying==-1) return;
00347                 _nPlaying = ((resume==true) ? 1 : 0);
00348                 for (var i:String in _aTweens) {
00349                         var o:Object = _aTweens[i];
00350                         var t:Object = o.targ;
00351                         var p:Object = o.props;
00352                         if (resume==true) {
00353                                 // Is pause intact? Target/prop could have been manipulated since it was paused here.
00354                                 var missing:Array = [];
00355                                 var oldTL:Number = _aTweens.length;
00356                                 for (var j:String in p) {
00357                                         if (_ZigoEngine.isTweenPaused(t,p[j])==false) missing.push(p[j]);
00358                                 }
00359                                 if (missing.length>0) {
00360                                         onTweenEnd({__zigoID__:o.targZID, props:missing, isResume:true});
00361                                 }
00362                                 if (_aTweens.length==oldTL) { // otherwise onTweenEnd removed the tween
00363                                         t.addListener(this);
00364                                         _ZigoEngine.unpauseTween(t, o.props);
00365                                 }
00366                         }
00367                         else {
00368                                 t.removeListener(this);
00369                                 _ZigoEngine.pauseTween(t, o.props);
00370                         }
00371                 }
00372                 if (resume==true && !(_aTweens.length>0)) { // no tweens.
00373                         complete();
00374                 }
00375                 else if (resume==true) {
00376                         _ZigoEngine.addListener(this);
00377                 }
00378                 else {
00379                         _ZigoEngine.removeListener(this);
00380                 }
00381         }
00382         
00387         public function destroy():Void
00388         {
00389                 var doRemove:Boolean = (_nPlaying>-1);
00390                 _nPlaying = -1;
00391                 for (var i:String in _aTweens) {
00392                         var o:Object = _aTweens[i];
00393                         o.targ.removeListener(this);
00394                         if (doRemove==true) _ZigoEngine.removeTween(o.targ, o.props);
00395                         delete _aTweens[i];
00396                 }
00397                 for (var j:String in this) {
00398                         delete this[j];
00399                 }
00400         }
00401         
00405         private function dispatchRequest(type:String, args:Array):Void
00406         {// avoids import of Fuse class since FuseItem can be used with ZigoEngine as an Object Syntax extension
00407                 var f:Object = _global.com.mosesSupposes.fuse.Fuse.getInstance(_nFuseID); 
00408                 if (!(args instanceof Array) && args!=null) args = (new Array(args));
00409                 Function(f[type]).apply(f, args);
00410         }
00411         
00412         // 2.
00413         
00418         private function _sID():String // like "Fuse#0>Item#0"
00419         {
00420                 var str:String;
00421                 if (_nFuseID==-1) {
00422                         str = 'One-off tween ';
00423                 }
00424                 else {
00425                         var fuse:Object = _global.com.mosesSupposes.fuse.Fuse.getInstance(_nFuseID);
00426                         str = 'Fuse#'+String(_nFuseID);
00427                         if (fuse.label!=undefined) str+=':"'+fuse.label+'"';
00428                 }
00429                 str+='>Item#'+String(_nItemID);
00430                 if (_oElements.label!=undefined) str+=':"'+_oElements.label+'"';
00431                 return str;
00432         }
00433         
00441         public function FuseItem (id:Number, o:Object, fuseID:Number)
00442         {
00443                 _ZigoEngine = _global.com.mosesSupposes.fuse.ZigoEngine;
00444                 this._nItemID = id;
00445                 this._nFuseID = fuseID;
00446                 this._initObj = o;
00447                 
00448                 _aProfiles = [];
00449                 _oElements = { aEvents:[] };
00450                 _oTemps = {};
00451                 if (!(o instanceof Array)) o = [o];
00452                 var fuse:Object = _global.com.mosesSupposes.fuse.Fuse;
00453                 _oTemps.outputLevel = (fuse!=undefined) ? fuse.OUTPUT_LEVEL : _global.com.mosesSupposes.fuse.ZigoEngine.OUTPUT_LEVEL;
00454                 
00455                 // v2 Command actions can only contain delay, label, scope, args and may not be nested in groups.
00456                 if (o.length==1) {
00457                         var o0:Object = o[0];
00458                         var obj:Object = (o0.action!=undefined) ? o0.action : o0;
00459                         if (obj.__buildMode!=true && obj.command!=undefined) {
00460                                 _oElements.command = obj.command;
00461                                 _oElements.scope = obj.scope; // v2.0: changed commandscope & commandargs to scope, args.
00462                                 _oElements.args = obj.args;
00463                                 _sImage = ' Elements:['+('command'+((typeof obj.command=='string') ? ':"'+obj.command+'", ' : ', '));
00464                                 if (obj.label!=undefined && typeof obj.label=='string') {
00465                                         _sImage+=('label:"'+obj.label+'", ');
00466                                         _oElements.label = obj.label; // one label per Command Action
00467                                 }
00468                                 if (obj.delay!=undefined) {
00469                                         _sImage+='delay, ';
00470                                         _oElements.delay = obj.delay; // one delay per Command Action
00471                                 }
00472                                 if (obj.func!=undefined && _oTemps.outputLevel>0) FuseKitCommon.error('113');
00473                                 return;
00474                         }
00475                 }
00476                 
00477                 // persistant vars for looping through actions
00478                 _oTemps.sImgS = '';
00479                 _oTemps.sImgE = '';
00480                 _oTemps.sImgB = '';
00481                 _oTemps.afl = 0;
00482                 _oTemps.ael = 0;
00483                 _oTemps.twDelayFlag = false;
00484                 _oTemps.nActions = o.length;
00485                 _oTemps.fuseProps = FuseKitCommon._fuseprops();
00486                 _oTemps.cbProps = FuseKitCommon._cbprops();
00487                 _oTemps.sUP = FuseKitCommon._underscoreable();
00488                 _oTemps.sCT = FuseKitCommon._cts();
00489                 _oTemps.bTriggerFound = false;
00490                 
00491                 // Parse each profile.
00492                 for (var i:String in o) {
00493                         var item:Object = o[i];
00494                         if (item.label!=undefined && typeof item.label=='string') _oElements.label = item.label; // one string-only label per FuseItem
00495                         var a:Object;
00496                         var aap:Object;
00497                         var bApplied:Boolean = Boolean(typeof item.action=='object' && !(item.action instanceof Array)); // reject arrays in action param!
00498                         if (bApplied==true) {
00499                                 a = item.action;
00500                                 aap = { // applied-action profile, these props are mixed into the action during parseProfile.
00501                                         delay:item.delay,
00502                                         target:item.target,
00503                                         addTarget:item.addTarget,
00504                                         label:item.label,
00505                                         trigger:item.trigger
00506                                 };
00507                         }
00508                         else {
00509                                 a = item;
00510                         }
00511                         var oPr:Object = parseProfile(a, aap);
00512                         if (oPr!=undefined) {
00513                                 _aProfiles.unshift(oPr);
00514                         }
00515                 }
00516                 
00517                 // build string image (if a command was passed in, this happens up top.)
00518                 _sImage = '';
00519                 var str:String = '';
00520                 if (_oElements.label!=undefined) str+=('label:"'+_oElements.label+'", ');
00521                 if (_oTemps.afl>0) str+= ((_oTemps.afl>1) ? _oTemps.afl+' callbacks, ' : 'callback, ');
00522                 if (_oElements.delay!=undefined || _oTemps.twDelayFlag==true) str+='delay, ';
00523                 if (_oTemps.bTriggerFound==true) str+='trigger, ';
00524                 if (_oTemps.ael>0) str+= ((_oTemps.ael>1) ? _oTemps.ael+' events, ' : 'event, ');
00525                 if (str!='') _sImage+=' Elements:['+(str.slice(0,-2))+']';
00526                 if (_oTemps.sImgS!='') _sImage+= ' StartProps:['+(_oTemps.sImgS.slice(0,-2))+']'; // careful: "StartProps:" is checked in evtSetStart
00527                 if (_oTemps.sImgE!='') _sImage+= ' Props:['+(_oTemps.sImgE.slice(0,-2))+']';
00528                 if (_oTemps.sImgB!='') _sImage+= ' Simple Syntax Props:['+(_oTemps.sImgB.slice(0,-1))+']';
00529                 delete _oTemps;
00530         }
00531         
00539         private function parseProfile(obj:Object, aap:Object):Object 
00540         {
00541                 var i:String, j:String, k:String;
00542                 // Build Mode (simple syntax) objects
00543                 if (obj.__buildMode==true) {
00544                         if (obj.command!=undefined) {
00545                                 if (obj.command=='delay') { // addCommand('delay',Number)
00546                                         _oElements.delay = obj.commandargs;
00547                                 }
00548                                 else {
00549                                         _oElements.command = obj.command;
00550                                         _oElements.args = obj.commandargs;
00551                                 }
00552                         }
00553                         if (obj.func!=undefined) {
00554                                 _oTemps.afl++;
00555                                 _oElements.aEvents.unshift({f:obj.func,s:obj.scope,a:obj.args});
00556                         }
00557                         if (obj.tweenargs!=undefined) {
00558                                 _oTemps.sImgB += (obj.tweenargs[1].toString()+','); // (allowing duplicates in simple syntax props image to save code, since it could be comma-delim str)
00559                                 return obj;
00560                         }
00561                         return null;
00562                 }
00563                 var oPr:Object = {
00564                         delay:(aap.delay!=undefined) ? aap.delay : obj.delay,
00565                         ease:obj.ease,
00566                         seconds:obj.seconds,
00567                         event:obj.event,
00568                         eventparams:obj.eventparams,
00569                         skipLevel:(typeof obj.skipLevel=='number' && obj.skipLevel>=0 && obj.skipLevel<=2) ? obj.skipLevel : _ZigoEngine.SKIP_LEVEL, // correct early for use in FuseItem.doTweens
00570                         oSP:{},
00571                         oEP:{},
00572                         oAFV:{}
00573                 };
00574                 // trigger
00575                 var trigger:Object = ((aap.trigger!=undefined) ? aap.trigger : obj.trigger); // can be true or number, not parsed until doTweens
00576                 if (trigger!=undefined) {
00577                         if (_oTemps.bTriggerFound==false) { // only one trigger is allowed per FuseItem
00578                                 oPr.trigger = trigger;
00579                                 _oTemps.bTriggerFound = true;
00580                         }
00581                         else if (_oTemps.outputLevel>0) {
00582                                 FuseKitCommon.error('126',(_sID()),trigger);
00583                         }
00584                 }
00585                 // synonyms
00586                 if (oPr.delay==undefined) oPr.delay = obj.startAt; 
00587                 if (oPr.ease==undefined) oPr.ease = obj.easing; // synonym (cannot use OR eval with string for some reason)
00588                 if (oPr.seconds==undefined) oPr.seconds = ((obj.duration!=undefined) ? obj.duration : obj.time); // synonym (cannot use OR eval with string for some reason)
00589 
00590                 // applied action target param overrides action target param
00591                 if (aap.target!=undefined) oPr.target = ((aap.target instanceof Array) ? aap.target : [aap.target]);
00592                 else if (obj.target!=undefined) oPr.target = ((obj.target instanceof Array) ? obj.target : [obj.target]);
00593                 // applied action addTarget param adds to action addTarget param (don't change order)
00594                 if (obj.addTarget!=undefined) oPr.addTarget = ((obj.addTarget instanceof Array) ? obj.addTarget : [obj.addTarget]);
00595                 if (aap.addTarget!=undefined) {
00596                         if (oPr.addTarget==undefined) oPr.addTarget = ((aap.addTarget instanceof Array) ? aap.addTarget : [aap.addTarget]);
00597                         else oPr.addTarget = ((oPr.addTarget instanceof Array) ? (oPr.addTarget.concat(aap.addTarget)) : ((new Array(oPr.addTarget)).concat(aap.addTarget)));
00598                 }
00599                 var bTwFlag:Boolean = false;
00600                 for (j in obj) {
00601                         var v:Object = obj[j];
00602                         if ((_oTemps.cbProps).indexOf('|'+j+'|')>-1) {//'|cycles|easyfunc|func|scope|args|startfunc|startscope|startargs|updfunc|updscope|updargs|extra1|extra2|'
00603                                 if (j!='skipLevel') oPr[j] = v;
00604                                 continue;
00605                         }
00606                         if ((_oTemps.fuseProps).indexOf('|'+j+'|')>-1) {//'|command|label|delay|event|eventparams|target|addTarget|trigger|startAt|ease|easing|seconds|duration|time|'
00607                                 if (j=='command' && _oTemps.nActions>1 && _oTemps.outputLevel>0) FuseKitCommon.error('114',String(v));
00608                                 continue;
00609                         }
00610                         if (typeof v=='object') {
00611                                 var copy:Object = (v instanceof Array) ? ([]) : {};
00612                                 for (k in v) copy[k] = v[k];
00613                                 v = copy;
00614                         }
00615                         var se:Object;
00616                         var seCP:Object;
00617                         if (j.indexOf('start')==0) {
00618                                 j = j.slice(6);
00619                                 se = oPr.oSP;
00620                         }
00621                         else {
00622                                 se = oPr.oEP;
00623                         }
00624                         if (ADD_UNDERSCORES==true && _oTemps.sUP.indexOf('|_'+j+'|')>-1) j='_'+j;
00625                         if (_oTemps.sCT.indexOf('|'+j+'|')>-1) {
00626                                 var addPct:Boolean = (j=='_tintPercent' && se.colorProp.p=='_tint');
00627                                 var addTint:Boolean = (j=='_tint' && se.colorProp.p=='_tintPercent');
00628                                 if (se.colorProp==undefined || addPct==true || addTint==true) { // write only 1 color prop per profile, saves cleanup work during tween.
00629                                         if (addPct==true) se.colorProp = {p:'_tint', v:{ tint:se.colorProp.v, percent:v }};
00630                                         else if (addTint==true) se.colorProp = {p:'_tint', v:{ tint:v, percent:se.colorProp.v }};
00631                                         else se.colorProp = {p:j, v:v};
00632                                         bTwFlag = true;
00633                                 }
00634                                 else if (_oTemps.outputLevel>0) {
00635                                         FuseKitCommon.error('115',(_sID()),j);
00636                                 }
00637                         }
00638                         else if (v!=null) { // (null values are only accepted for color props)
00639                                 if (se==oPr.oEP && (obj.controlX!=undefined || obj.controlY!=undefined) && (j.indexOf('control')==0 || j=='_x' || j=='_y')) { // group bezier end props
00640                                         if (se._bezier_==undefined) se._bezier_ = {};
00641                                         if (j.indexOf('control')==0) se._bezier_[j] = v; //controlX, controlY
00642                                         else (se._bezier_[(j.charAt(1))] = v); // x, y
00643                                 }
00644                                 else {
00645                                         se[j] = v;
00646                                 }
00647                                 bTwFlag = true;
00648                         }
00649                 } // end parse props(j), still looping through actions(i)
00650                 
00651                 /* Special "Nontween delay" cases
00652                  * (Note that normally delays are played by parent fuse except in these cases)
00653                  *  -start/update callbacks without any tween props
00654                  *  -delay within multi-item group
00655                  */ 
00656                 if (bTwFlag==false && (oPr.trigger!=undefined || 
00657                                                                 ((oPr.delay!=undefined || oPr.seconds!=undefined) &&
00658                                                                          ( (oPr.startfunc!=undefined || oPr.updfunc!=undefined)
00659                                                                            || (oPr.func!=undefined && _oTemps.nActions>1) )))) {
00660                         if (_ZigoEngine==undefined) { // ignore output level for crucial error message
00661                                 FuseKitCommon.error('116');
00662                         }
00663                         else {
00664                                 if (oPr.func!=undefined) _oTemps.afl++;
00665                                 if (oPr.event!=undefined) _oTemps.ael++;
00666                                 oPr._doTimer = true;
00667                                 if (oPr.delay!=undefined) _oTemps.twDelayFlag = true;
00668                                 return oPr;
00669                         }
00670                 }
00671                 if (bTwFlag==true) { // do a final round of cleanup on tween profile and build string image
00672                         var bEC:Boolean = (oPr.oEP.colorProp!=undefined);
00673                         for (var l:Number=0; l<2; l++) {
00674                                 var se:Object = (l==0) ? oPr.oSP : oPr.oEP;
00675                                 var str:String = (l==0) ? _oTemps.sImgS : _oTemps.sImgE;
00676                                 var sCP:String = se.colorProp.p;
00677                                 if (sCP!=undefined) { // combine color back in (colorProp was used to enforce single start/end color)
00678                                         se[sCP] = se.colorProp.v;
00679                                         delete se.colorProp;
00680                                 }
00681                                 if ((se._xscale!=undefined || se._scale!=undefined) && (se._width!=undefined || se._size!=undefined)) {
00682                                         var discard:String = (se._xscale!=undefined) ? '_xscale' : '_scale';
00683                                         delete se[discard];
00684                                         if (_oTemps.outputLevel>0) FuseKitCommon.error('115',(_sID()),discard);
00685                                 }
00686                                 if ((se._yscale!=undefined || se._scale!=undefined) && (se._height!=undefined || se._size!=undefined)) {
00687                                         var discard:String = (se._yscale!=undefined) ? '_yscale' : '_scale';
00688                                         delete se[discard];
00689                                         if (_oTemps.outputLevel>0) FuseKitCommon.error('115',(_sID()),discard);
00690                                 }
00691                                 for (j in se) {
00692                                         if (str.indexOf(j+', ')==-1) str+=(j+', ');
00693                                         if (se==oPr.oSP) {
00694                                                 if (oPr.oEP[j]==undefined && !(j==sCP && bEC==true)) { // add 'autofill' lookup
00695                                                         oPr.oAFV[j] = true;
00696                                                         oPr.oEP[j] = [];
00697                                                 }
00698                                         }
00699                                 }
00700                                 ((l==0) ? _oTemps.sImgS = str : _oTemps.sImgE = str);
00701                         }
00702                         return oPr;
00703                 }
00704                 // If no tweens were added or start/end profiles ended up empty, move usable props to _oElements
00705                 if (oPr.delay!=undefined && _oTemps.nActions==1) { // single-item actions only, see first if() in this block for multi-item actions
00706                         _oElements.delay = oPr.delay;
00707                         _oElements.delayscope = oPr.scope; // (internal, not a valid user prop!)
00708                 }
00709                 if (oPr.event!=undefined) {
00710                         _oTemps.ael++;
00711                         _oElements.aEvents.unshift({e:oPr.event, s:oPr.scope, ep:oPr.eventparams, skipLevel:oPr.skipLevel});
00712                 }
00713                 // actions containing startfunc/updfunc are handled w/nonTweenDelay.
00714                 var oldL:Number = _oElements.aEvents.length;
00715                 if (oPr.easyfunc!=undefined) _oElements.aEvents.push({cb:oPr.easyfunc, s:oPr.scope, skipLevel:oPr.skipLevel});
00716                 if (oPr.func!=undefined) _oElements.aEvents.push({f:oPr.func, s:oPr.scope, a:oPr.args, skipLevel:oPr.skipLevel});
00717                 _oTemps.afl+=(_oElements.aEvents.length-oldL);
00718                 delete oPr;
00719                 return undefined;
00720         }
00721         
00722         // 3.
00723         
00732         private function doTweens(targs:Array, defaultScope:Object, setStart:Boolean):String
00733         {
00734                 if (_aTweens==null) {
00735                         this._aTweens = [];
00736                 }
00737                 var fuse:Object = _global.com.mosesSupposes.fuse.Fuse;
00738                 var outputLevel:Number = (fuse!=undefined) ? fuse.OUTPUT_LEVEL : _ZigoEngine.OUTPUT_LEVEL;
00739                 var propsAdded:String = '';
00740                 var nTgErrors:Number = 0;
00741                 var i:String, j:String, k:String;
00742                 // Build-Mode FuseItem (startprops option doesn't exist here)----------
00743                 if ((_aProfiles[0]).__buildMode==true) { 
00744                         for (var h:Number=0; h<_aProfiles.length; h++) {
00745                                 var twArgs:Array = (_aProfiles[h]).tweenargs;
00746                                 if ((twArgs[6]).cycles===0 || ((twArgs[6]).cycles.toUpperCase())=='LOOP') {
00747                                         delete (twArgs[6]).cycles;
00748                                         if (outputLevel>0) FuseKitCommon.error('117',(_sID()));
00749                                 }
00750                                 var sProps:String = (_ZigoEngine.doTween.apply(_ZigoEngine, twArgs));
00751                                 var aProps:Array = ((sProps==null) ? [] : (sProps).split(','));
00752                                 if (aProps.length>0) {
00753                                         _aTweens.push({targ:(twArgs[0]), props:aProps, targZID:(twArgs[0]).__zigoID__});
00754                                         (twArgs[0]).addListener(this);
00755                                         for (j in aProps) if (propsAdded.indexOf(aProps[j]+',')==-1) propsAdded+=(aProps[j]+',');
00756                                 }
00757                                 if (outputLevel==3) FuseKitCommon.output('\n-'+(_sID())+' TWEEN (simple syntax)\n\ttargets:['+twArgs[0]+']\n\tprops sent:['+twArgs[1]+']');
00758                         }
00759                         return ((propsAdded=='') ? null : propsAdded.slice(0,-1));
00760                 }
00761                 // Normal setStart, tweens ---------------------------------------------
00762                 var doSetStarts:Boolean = (_bStartSet!=true && (setStart==true || _sImage.indexOf('StartProps:')>-1));
00763                 // cycling through each action profile
00764                 for (var h:Number=0; h<_aProfiles.length; h++) 
00765                 {
00766                         var pr:Object = _aProfiles[h];
00767                         // Set scope for callbacks + runtime-eval funcs.
00768                         // Each action may define a "scope" param which overrides Fuse default scope
00769                         var scope:Object = defaultScope; // this local is used many times within this loop for runtime-eval
00770                         if (pr.scope!=undefined) {
00771                                 // scope param can be a runtime func (or delegate) that uses Fuse default scope to eval. 
00772                                 // (The evaled scope will cascade to updscope & startscope if they are funcs.)
00773                                 scope = (pr.scope instanceof Function) ? pr.scope.apply(scope) : pr.scope;
00774                         }
00775                         // build event object
00776                         var event:Object;
00777                         if (pr.event!=undefined) {
00778                                 var evt:String = ((pr.event instanceof Function) ? pr.event.apply(scope) : pr.event);
00779                                 var evtparams:Object = ((pr.eventparams instanceof Function) ? pr.eventparams.apply(scope) : pr.eventparams);
00780                                 if (evt!=undefined && evt.length>0) {
00781                                         event = {e:evt, ep:evtparams, s:scope};
00782                                 }
00783                         }
00784                         // build callback object
00785                         var skipLevel:Boolean = ((pr.skipLevel instanceof Function) ? pr.skipLevel.apply(scope) : pr.skipLevel);
00786                         var oSimpleCB:Object = { skipLevel:skipLevel };
00787                         var oCB:Object = { skipLevel:skipLevel };
00788                         if (pr.cycles!=undefined) {
00789                                 var cycles:Object = ((pr.cycles instanceof Function) ? pr.cycles.apply(scope) : pr.cycles);
00790                                 if ((Number(cycles)==0 || (String(cycles).toUpperCase())=='LOOP') && fuse!=undefined) {
00791                                         delete pr.cycles;
00792                                         if (outputLevel>0) FuseKitCommon.error('117',(_sID())); // infinite cycles not allowed in fuses
00793                                 }
00794                                 else {
00795                                         oSimpleCB.cycles = oCB.cycles = cycles;
00796                                 }
00797                         }
00798                         var cbstr:String='';
00799                         if (pr.easyfunc!=undefined || pr.func!=undefined || pr.startfunc!=undefined || pr.updfunc!=undefined) {
00800                                 for (i in pr) {
00801                                         if (i.indexOf('func')>-1) {
00802                                                 oCB[i] = pr[i];
00803                                         }
00804                                         else if (i=='startscope' || i=='updscope' || i.indexOf('args')>-1) {
00805                                                 oCB[i] = (pr[i] instanceof Function) ? Function(pr[i]).apply(scope) : pr[i];
00806                                         }
00807                                 }
00808                                 if (scope!=undefined) {
00809                                         if (oCB.func!=undefined && oCB.scope==undefined) oCB.scope = scope; // auto-fill callback scopes where possible
00810                                         if (oCB.updfunc!=undefined && oCB.updscope==undefined) oCB.updscope = scope;
00811                                         if (oCB.startfunc!=undefined && oCB.startscope==undefined) oCB.startscope = scope;
00812                                 }
00813                         }
00814                         for (j in oCB) cbstr+=(j+':'+oCB[j]+'|');
00815                         // trigger: may be boolean, number, or runtime-eval function
00816                         var triggerTrue:Boolean = (pr.trigger===true);
00817                         var triggerTime:Number = undefined;
00818                         if (triggerTrue==false && pr.trigger!=undefined) {
00819                                 triggerTime = ((pr.trigger instanceof Function) ? pr.trigger.apply(scope) : pr.trigger);
00820                                 if (typeof triggerTime=='string') {
00821                                         triggerTime = ((String(triggerTime).charAt(0)=='-') ? -(parseClock(String(triggerTime).slice(1))) : (parseClock(String(triggerTime))));
00822                                 }
00823                                 if (_global.isNaN(triggerTime)==true) triggerTime = undefined;
00824                         }
00825                         
00826                         // Targets
00827                         // evaluated targets + addTargets
00828                         var targets:Array = []; 
00829                         var aBase:Array = (pr.target==undefined) ? targs : pr.target; 
00830                         var aTemp:Array = [];
00831                         var bTgError:Boolean = false;
00832                         // (any runtime func (or delegate) may return one targ or an array of targs)
00833                         for (i in aBase) { 
00834                                 var v:Object = aBase[i];
00835                                 aTemp = aTemp.concat((v instanceof Function) ? v.apply(scope) : v);
00836                         }
00837                         for (i in pr.addTarget) {
00838                                 var v:Object = pr.addTarget[i];
00839                                 aTemp = aTemp.concat((v instanceof Function) ? v.apply(scope) : v);
00840                         }
00841                         for (i in aTemp) {
00842                                 var v:Object = aTemp[i];
00843                                 if (v!=null) {
00844                                         var exists:Boolean = false;
00845                                         for (j in targets) {
00846                                                 if (targets[j]==v) {
00847                                                         exists = true;
00848                                                         break;
00849                                                 }
00850                                         }
00851                                         if (exists==false) targets.unshift(v);
00852                                 }
00853                                 else {
00854                                         bTgError = true;
00855                                 }
00856                         }
00857                         var noTargError:Boolean = (targets.length==0 && pr._doTimer!=true);
00858                         var doTimer:Boolean = (pr._doTimer==true && targets.length==0);
00859                         if (bTgError==true || noTargError==true) {
00860                                 nTgErrors++;
00861                                 if (noTargError==true) {
00862                                         continue;
00863                                 }
00864                         }
00865                         // -- 1. start props --
00866                         if (doSetStarts==true)
00867                         {
00868                                 // generate one ZigoEngine.doTween() call per target. Props parsed for runtime-eval, bools, validation
00869                                 for (i in targets) { 
00870                                         var targ:Object = targets[i];
00871                                         var aSP:Array = [];
00872                                         var aSV:Array = [];
00873                                         if (setStart==true) {
00874                                                 for (var q:String in pr.oEP) {
00875                                                         // Use 3rd param createNew to pre-create any missing filters on setStartProps, so the filter doesn't suddenly appear just before that action starts.
00876                                                         _global.com.mosesSupposes.fuse.FuseFMP.getFilterProp(targ,q,true); 
00877                                                 }
00878                                         }
00879                                         for (var p:String in pr.oSP) {
00880                                                 var v:Object = pr.oSP[p];
00881                                                 if (v instanceof Function) v = v.apply(scope);
00882                                                 if (v===true || v===false) { // set start booleans immediately. 
00883                                                         targ[p] = v;
00884                                                         if (pr.oAFV[p]==true) { // prohibit autofill with booleans.
00885                                                                 for (k in pr.oEP[p]) if (pr.oEP[p][k].targ==targ) pr.oEP[p].splice(Number(k),1);
00886                                                                 pr.oEP[p].push({targ:targ,val:'IGNORE'});
00887                                                         }
00888                                                         continue;
00889                                                 }
00890                                                 // autofill missing end values. Assume resets for known properties, otherwise take a snapshot of the current value to return to.
00891                                                 if (pr.oAFV[p]==true && !(p=='_colorReset' && v==100) && !(p=='_tintPercent' && v==0)) {// if no endprop was passed for startprop, store current value (does not apply to color prop which resets, preset during constructor parse)
00892                                                         var afv:Object;
00893                                                         if (p=='_tint' || p=='_colorTransform') {
00894                                                                 afv = _ZigoEngine.getColorTransObj();
00895                                                         }
00896                                                         else if (('|_alpha|_contrast|_invertColor|_tintPercent|_xscale|_yscale|_scale|').indexOf('|'+p+'|')>-1) {
00897                                                                 afv = 100;
00898                                                         }
00899                                                         else if (('|_brightness|_brightOffset|_colorReset|_rotation|').indexOf('|'+p+'|')>-1) {
00900                                                                 afv = 0;
00901                                                         }
00902                                                         else { // snapshot current val, retaining target (which is important in the case of relative endvals)
00903                                                                 var fmpVal:Number = _global.com.mosesSupposes.fuse.FuseFMP.getFilterProp(targ,p,true);
00904                                                                 if (fmpVal!=null) afv = fmpVal;
00905                                                                 else afv = (_global.isNaN(targ[p])==false) ? targ[p] : 0;
00906                                                         }
00907                                                         for (k in pr.oEP[p]) if (pr.oEP[p][k].targ==targ) pr.oEP[p].splice(Number(k),1);
00908                                                         pr.oEP[p].push({targ:targ,val:afv});
00909                                                 }
00910                                                 if (typeof v=='object') {
00911                                                         var copy:Object = (v instanceof Array) ? ([]) : {};
00912                                                         for (k in v) copy[k] = ((v[k]) instanceof Function) ? Function(v[k]).apply(scope) : v[k];
00913                                                         v = copy;
00914                                                 }
00915                                                 aSP.push(p);
00916                                                 aSV.push(v);
00917                                         }// end startprops loop(n)
00918                                         
00919                                         // set starts using egine, which monitors/broadcasts interrupts + parses complex properties.
00920                                         if (aSV.length>0) {
00921                                                 if (outputLevel==3) FuseKitCommon.output('-'+(_sID())+' '+targ+' SET STARTS: '+['['+aSP+']', '['+aSV+']']);
00922                                                 _ZigoEngine.doTween(targ, aSP, aSV, 0);
00923                                         }
00924                                 } // end set starts
00925                         }// end if startprops
00926                         
00927                         if (setStart==true) {
00928                                 continue;
00929                         }
00930                         
00931                         // -- 2. end props --
00932                         // Generate one ZigoEngine.doTween() call per target since envals can differ due to auto-fill feature. 
00933                         // the last round of evaluating seconds, delay, and booleans is saved for the pickup round that happens after this loop
00934                         var seconds:Number;
00935                         var delay:Number;
00936                         var booleans:Object;// Group end-booleans per target to be set in onTweenEnd
00937                         var tweenSuccess:Boolean = false;
00938                         var targsOrProxy:Array = ((doTimer==false) ? targets : [0]);// force loop to occur once for targetless timer tweens
00939                         for (i in targsOrProxy) { 
00940                                 // Eval other per-profile params (putting this in the loop is less efficient but it allows runtime-eval-funcs to be run per target.)
00941                                 // Q: when a user builds an action and there are multiple targets, do they want getters to be fired per target, or per action?
00942                                 var ease:Object = pr.ease;
00943                                 if (ease instanceof Function) { // could be a runtime eval function!
00944                                         var ef:Function = (Function(ease));
00945                                         if (typeof ef(1,1,1,1)!='number') ease = ef.apply(scope); // it's not a valid easing equation the engine can use.
00946                                 }
00947                                 seconds = (pr.seconds instanceof Function) ? pr.seconds.apply(scope) : pr.seconds;
00948                                 if (seconds!=undefined) {
00949                                         if (typeof seconds=='string') seconds = (parseClock(String(seconds)));
00950                                         if (_global.isNaN(seconds)==true) seconds = (_ZigoEngine.DURATION || 0);
00951                                 }
00952                                 delay = (pr.delay instanceof Function) ? pr.delay.apply(scope) : pr.delay;
00953                                 if (typeof delay=='string') delay = (parseClock(String(delay)));
00954                                 if (delay==null || _global.isNaN(delay)==true) delay = 0;
00955                                 if (doTimer==true) continue;
00956                                 // ---------------------------------------------------------------
00957                                 //parse
00958                                 var targ:Object = targsOrProxy[i];
00959                                 var aEP:Array = [];
00960                                 var aEV:Array = [];
00961                                 var numBools:Number = 0;
00962                                 for (var p:String in pr.oEP) {
00963                                         var v:Object = pr.oEP[p];
00964                                         if (v instanceof Function) {
00965                                                 v = v.apply(scope);
00966                                         }
00967                                         if (v===true || v===false) { // end booleans will be attached to a tween & set in onTweenEnd.
00968                                                 if (booleans==undefined) booleans = {};
00969                                                 booleans[p] = v;
00970                                                 numBools++;
00971                                                 continue;
00972                                         }
00973                                         if (typeof v=='object') {
00974                                                 if ((v[0]).targ!=undefined) { // this is an autofilled property - match targets.
00975                                                         for (k in v) {
00976                                                                 if ((v[k]).targ==targ) {
00977                                                                         v = (v[k]).val;
00978                                                                         break;
00979                                                                 }
00980                                                         }
00981                                                 }
00982                                                 else {
00983                                                         var copy:Object = (v instanceof Array) ? ([]) : {};
00984                                                         for (k in v) copy[k] = ((v[k]) instanceof Function) ? Function(v[k]).apply(scope) : v[k];
00985                                                         v = copy;
00986                                                 }
00987                                         }
00988                                         if (v!='IGNORE') {
00989                                                 aEP.push(p);
00990                                                 aEV.push(v);
00991                                         }
00992                                 } // end endprops loop(n)
00993                                 
00994                                 // normal tweens. monitor only the props that are added to the engine's tweenlist.
00995                                 var aProps:Array = [];
00996                                 if (aEV.length>0) {
00997                                         // Only add callbacks/booleans/events in the case of single target - otherwise these things will be picked up with a fake tween later.
00998                                         var sProps:String = _ZigoEngine.doTween(targ, aEP, aEV, seconds, ease, delay, oCB);
00999                                         if (sProps!=null) aProps = (sProps.split(','));
01000                                         if (aProps.length>0) {
01001                                                 var to:Object = {targ:targ, props:aProps, bools:booleans, targZID:targ.__zigoID__};
01002                                                 if (tweenSuccess==false) {
01003                                                         // Important: callback, event, trigger:true need to only be added once per profile.
01004                                                         oCB = oSimpleCB;
01005                                                         to.event = event;
01006                                                         event = booleans = undefined;
01007                                                         to.trigger = triggerTrue; // single-target profile with trigger:true
01008                                                 }
01009                                                 _aTweens.push(to);
01010                                                 targ.addListener(this);
01011                                                 tweenSuccess = true;
01012                                         }
01013                                         for (j in aProps) if (propsAdded.indexOf(aProps[j]+',')==-1) propsAdded+=(aProps[j]+',');
01014                                         // TRACE TWEENS (lets you know if one or more props didn't get added)
01015                                         if (outputLevel==3) {
01016                                                 var epstr:String = aEP.toString();
01017                                                 if (aProps.length>aEP.length) epstr += ('\n\t[NO-CHANGE PROPS DISCARDED. KEPT:'+sProps+']');
01018                                                 var evstr:String = '';
01019                                                 for (j in aEV) evstr=(((typeof aEV[j]=='string')?'"'+aEV[j]+'"':aEV[j]) + ', '+evstr);
01020                                                 FuseKitCommon.output('\n-'+(_sID())+' TWEEN:\n'+(['\t[getTimer():'+getTimer()+'] ','targ: '+targ, 'props: '+epstr, 'endVals: '+evstr, 'time: '+((seconds==undefined) ? _ZigoEngine.DURATION : seconds), 'easing: '+((ease==undefined) ? _ZigoEngine.EASING : ease), 'delay: '+((delay==undefined) ? 0 : delay), 'callbacks: '+((cbstr=='') ? '(none)':cbstr)]).join('\n\t')); 
01021                                         }
01022                                 }
01023                         } // end targets loop(i)
01024                         
01025                         if (seconds==undefined || _global.isNaN(seconds)==true) seconds = 0;
01026                         var time:Number = delay+seconds;
01027                         
01028                         // time-based trigger: use a fake tween (trigger time must be less than tween duration+delay)
01029                         if (triggerTime!=undefined) {
01030                                 // Special option to use a negative trigger time, which is counted back from the end of the tween
01031                                 if (triggerTime<0) {
01032                                         triggerTime += time;
01033                                 }
01034                                 if (triggerTime>0 && (time==0 || triggerTime<time)) {
01035                                         if (time==0) {
01036                                                 // action has trigger plus callback/event/booleans but no delay or tween time - include these things in the trigger delay.
01037                                                 if (outputLevel==3) { FuseKitCommon.output('-'+(_sID())+' graft a timed trigger ('+triggerTime+' sec). [has callback:'+(oCB!=oSimpleCB)+', has event:'+(event!=undefined)+', has booleans:'+(booleans!=undefined)+']'); }
01038                                                 doTimerTween(null, triggerTime, 0, true, booleans, oCB, event);
01039                                                 tweenSuccess = true;
01040                                         }
01041                                         else {
01042                                                 // action has trigger plus a delay or other tweens, create a separate trigger delay and save other items for final pickup
01043                                                 if (outputLevel==3) { FuseKitCommon.output('-'+(_sID())+' graft a timed trigger ('+triggerTime+' sec).'); }
01044                                                 doTimerTween(null, triggerTime, 0, true);
01045                                         }
01046                                 }
01047                                 else if (outputLevel==3) { FuseKitCommon.output('-'+(_sID())+' timed trigger discarded: out of range. ['+triggerTime+'/'+time+']'); }
01048                         }
01049                         
01050                         // If nothing tweened, pick up any booleans, callbacks, and custom event.
01051                         if (tweenSuccess==false && (oCB!=oSimpleCB || event!=undefined || booleans!=undefined)) {
01052                                 if (skipLevel==0 && time>0) { // run a tweened delay before doing callbacks, booleans & events
01053                                         if (outputLevel==3) { FuseKitCommon.output('-'+(_sID())+' no props tweened - graft a delay ('+time+' sec). [has callback:'+(oCB!=oSimpleCB)+', has event:'+(event!=undefined)+', has booleans:'+(booleans!=undefined)+']'); }
01054                                         doTimerTween(targets, seconds, delay, triggerTrue, booleans, oCB, event);
01055                                 }
01056                                 else { // immediate wrap-up
01057                                         if (outputLevel==3) { FuseKitCommon.output('-'+(_sID())+' no props tweened, executing nontween items. [has callback:'+(oCB!=oSimpleCB)+', has event:'+(event!=undefined)+', has booleans:'+(booleans!=undefined)+']'); }
01058                                         for (i in targets) {
01059                                                 for (j in booleans) targets[i][j] = booleans[j]; // set end booleans
01060                                         }
01061                                         if (skipLevel<2) {// If skipLevel is 2 in all actions and no tweens succeed it will go unfired.
01062                                                 if (oCB!=undefined) {
01063                                                         if (oCB.startfunc!=undefined) fireEvents({f:oCB.startfunc,s:oCB.startscope,a:oCB.startargs},scope,outputLevel);
01064                                                         if (oCB.updfunc!=undefined) fireEvents({f:oCB.updfunc,s:oCB.updscope,a:oCB.updargs},scope,outputLevel);
01065                                                         if (oCB.startfunc!=undefined || oCB.easyfunc!=undefined) fireEvents({f:oCB.func,s:oCB.scope,a:oCB.args,cb:oCB.easyfunc},scope,outputLevel);
01066                                                 } 
01067                                                 if (event!=undefined) {
01068                                                         fireEvents(event);
01069                                                 }
01070                                         }
01071                                 }
01072                         }
01073                 } // end profiles loop(h)
01074                 if (nTgErrors>0 && outputLevel>0) {
01075                         if (nTgErrors==_aProfiles.length && propsAdded=='') FuseKitCommon.error('118',(_sID()),setStart);
01076                         else FuseKitCommon.error('119',doSetStarts,nTgErrors,(_sID()));
01077                 }
01078                 return ((propsAdded=='') ? null : propsAdded.slice(0,-1));
01079         }
01080         
01084         private function doTimerTween(actualTargets:Array, duration:Number, delay:Number, trigger:Boolean, booleans:Object, callback:Object, event:Object):Void
01085         {
01086                 var proxy:Object = { __TweenedDelay:0 };
01087                 _ZigoEngine.initializeTargets(proxy);
01088                 _aTweens.push({targ:proxy, props:['__TweenedDelay'], trigger:trigger, bools:booleans, event:event, actualTargs:actualTargets, targZID:proxy.__zigoID__ });
01089                 _ZigoEngine.doTween(proxy, '__TweenedDelay', 1, duration, null, delay, callback);
01090                 proxy.addListener(this);
01091         }
01092         
01098         private function onTweenEnd(o:Object):Void
01099         {
01100                 if (_nPlaying<1) return;
01101                 var fuse:Object = _global.com.mosesSupposes.fuse.Fuse;
01102                 var outputLevel:Number = (fuse!=undefined) ? fuse.OUTPUT_LEVEL : _ZigoEngine.OUTPUT_LEVEL;
01103                 if (outputLevel==3) FuseKitCommon.output('-'+(_sID())+' onTweenEnd: '+((typeof o.target=='movieclip')?o.target._name:(typeof o.target))+'['+o.props+'] [getTimer()='+getTimer()+']');
01104                 var id:Number = ((o.__zigoID__!==undefined) ? o.__zigoID__ : o.target.__zigoID__);
01105                 for (var i:String in _aTweens) {
01106                         var to:Object = _aTweens[i];
01107                         // safer to match ids since pause(resume) might be trying to clear out a missing target
01108                         if (to.targZID==id) { 
01109                                 for (var j:String in o.props) {
01110                                         var pa:Array = to.props;
01111                                         for (var k:String in pa) {
01112                                                 var p:String = pa[k];
01113                                                 if (p==o.props[j]) {
01114                                                         // interruption during doTweens looping
01115                                                         if (_nPlaying==2) { 
01116                                                                 if (outputLevel>0) FuseKitCommon.error('120',(_sID()),p);
01117                                                         }
01118                                                         pa.splice(Number(k), 1);
01119                                                         if (pa.length==0) {
01120                                                                 if (to.event!=undefined) {
01121                                                                         fireEvents(to.event, to.event.s, outputLevel);
01122                                                                 }
01123                                                                 if (p=='__TweenedDelay') {
01124                                                                         _ZigoEngine.deinitializeTargets(to.targ);
01125                                                                         delete to.targ; // try and dispose of the temp object
01126                                                                         // set boolean end vals to cached targets. (listeners: in theory if the fake tween passed targets at all it is because no tweens in this target group were added, therefore listeners should not have been added on the actual targets.)
01127                                                                         for (var m:String in to.bools) {
01128                                                                                 for (var t:String in to.actualTargs) {
01129                                                                                         to.actualTargs[t][m] = to.bools[m];
01130                                                                                 }
01131                                                                         }
01132                                                                 }
01133                                                                 else {
01134                                                                         var found:Boolean = false;
01135                                                                         for (var m:String in to.bools) { // set boolean end vals
01136                                                                                 to.targ[m] = to.bools[m];
01137                                                                         }
01138                                                                         for (var l:String in _aTweens) {
01139                                                                                 if (l!=i && (_aTweens[l]).targ==to.targ) found = true;
01140                                                                         }
01141                                                                         if (found==false) { // target done
01142                                                                                 to.targ.removeListener(this);
01143                                                                         }
01144                                                                 }
01145                                                                 if (to.trigger==true) {
01146                                                                         if (_bTrigger==false && o.isResume!=true && _aTweens.length>1) {
01147                                                                                 _bTrigger = true;
01148                                                                                 if (outputLevel==3) FuseKitCommon.output('-'+(_sID())+' trigger fired!');
01149                                                                                 var breakChainInt:Number;
01150                                                                                 breakChainInt = setInterval(function(fi:FuseItem) {
01151                                                                                         clearInterval(breakChainInt);
01152                                                                                         fi.dispatchRequest('advance',[false]);
01153                                                                                 },1,this);
01154                                                                         }
01155                                                                 }
01156                                                                 _aTweens.splice(Number(i),1);
01157                                                         }
01158                                                 }
01159                                         }
01160                                 }
01161                         }
01162                 }
01163                 if (_aTweens.length==0 && _nPlaying==1 && o.isResume!=true) { // tweens can be removed during pause(0) but don't advance.
01164                         complete(outputLevel);
01165                 }
01166         }
01167         
01173         private function onTweenInterrupt(o:Object):Void
01174         {
01175                 if (_nPlaying==-1) return;
01176                 var id:Number = o.__zigoID__;
01177                 var fuse:Object = _global.com.mosesSupposes.fuse.Fuse;
01178                 var outputLevel:Number = (fuse!=undefined) ? fuse.OUTPUT_LEVEL : _ZigoEngine.OUTPUT_LEVEL;
01179                 if (outputLevel==3) FuseKitCommon.output((_sID())+' property interrupt caught! '+o.target+',__zigoID__:'+id+'['+o.props+'].');
01180                 if (id==undefined || typeof o.target!='string') { 
01181                         onTweenEnd(o);
01182                         return;
01183                 }
01184                 for (var i:String in _aTweens) { // target went missing, quickly strip out all _aTween objs with that target
01185                         if ((_aTweens[i]).targZID==id) {
01186                                 _aTweens.splice(Number(i),1);
01187                         }
01188                 }
01189                 if (_aTweens.length==0 && _nPlaying==1) {
01190                         complete(outputLevel);
01191                 }
01192         }
01193         
01199         private function complete(outputLevel:Number):Void
01200         {
01201                 var trigger:Boolean = _bTrigger;
01202                 this.stop(); // will reset _nPlaying which is read by Fuse on last item.
01203                 if (trigger!=true) {
01204                         if (outputLevel==3) FuseKitCommon.output('-'+(_sID())+' complete.');
01205                 }
01206                 // Use a setInterval for callback-only items to avoid a continuous action list which can lock the player
01207                 var breakChainInt:Number;
01208                 breakChainInt = setInterval(function(fi:FuseItem) {
01209                         clearInterval(breakChainInt);
01210                         fi.dispatchRequest('advance',[trigger]);
01211                 },1,this);
01212         }
01213         
01220         private function parseClock(str:String):Number 
01221         { 
01222                 if (str.indexOf(':')!=2) {
01223                         FuseKitCommon.error('121');
01224                         return (_ZigoEngine.DURATION || 0);
01225                 }
01226                 var time:Number = 0;
01227                 var spl:Array = str.split(':');
01228                 spl.reverse();
01229                 var t:Number;
01230                 if (String(spl[0]).length==2 && _global.isNaN(t = Math.abs(Number(spl[0])))==false) time += (t/100);// hundredths
01231                 if (String(spl[1]).length==2 && _global.isNaN(t = Math.abs(Number(spl[1])))==false && t<60) time += t;// seconds
01232                 if (String(spl[2]).length==2 && _global.isNaN(t = Math.abs(Number(spl[2])))==false && t<60) time += (t*60);// minutes
01233                 if (String(spl[3]).length==2 && _global.isNaN(t = Math.abs(Number(spl[3])))==false && t<24) time += (t*3600);// hours - hah!
01234                 return time;
01235         }
01236         
01243         private function fireEvents(o:Object,scope:Object,outputLevel:Number):Void // logic should mirror core of ZigoEngine.parseCallback()
01244         {
01245                 var s:Object = (o.s!=null) ? o.s : scope;
01246                 if (o.e==undefined) { // callback
01247                         if (typeof o.cb=='string' && o.cb.length>0) {
01248                                 var parsed:Object = _global.com.mosesSupposes.fuse.Shortcuts.parseStringTypeCallback(o.cb);
01249                                 if (parsed.func!=undefined) {
01250                                         fireEvents({s:parsed.scope,f:parsed.func,a:parsed.args});
01251                                 }
01252                                 else if (outputLevel>0) {
01253                                         FuseKitCommon.error('122');
01254                                 }
01255                         }
01256                         if (o.f==undefined) return;
01257                         var f:Function = o.f;
01258                         if (typeof o.f=='string' && s[o.f]==undefined) { 
01259                                 if (_global[o.f]!=undefined) f = _global[o.f];
01260                                 if (_level0[o.f]!=undefined) f = _level0[o.f];
01261                         }
01262                         if (typeof f!='function') {
01263                                 if (typeof s[o.f]=='function') f = s[o.f];
01264                                 else f = eval(o.f); // last grasp
01265                         }
01266                         if (f==undefined) {
01267                                 if (outputLevel>0) FuseKitCommon.error('123');
01268                         }
01269                         else {
01270                                 var args:Array = (o.a instanceof Function) ? o.a.apply(s) : o.a;
01271                                 if (args!=undefined && !(args instanceof Array)) args = [args];
01272                                 f.apply(s, args);
01273                         }
01274                 }
01275                 else { // event (scope used only for runtime-eval)
01276                         var type:String = (o.e instanceof Function) ? String(o.e.apply(s)) : String(o.e);
01277                         if (type!='undefined' && type.length>0) {
01278                                 if (('|onStart|onStop|onPause|onResume|onAdvance|onComplete|').indexOf('|'+type+'|')>-1) {
01279                                         if (outputLevel>0) FuseKitCommon.error('124',type);
01280                                 }
01281                                 else {
01282                                         var fuse:Object = _global.com.mosesSupposes.fuse.Fuse.getInstance(_nFuseID);
01283                                         var evObj:Object = (o.ep instanceof Function) ? o.ep.apply(s) : o.ep;
01284                                         if (evObj==null || typeof evObj!='object') evObj = {};
01285                                         evObj.target = fuse;
01286                                         evObj.type = type;
01287                                         fuse.dispatchEvent.call(fuse,evObj); // make the Fuse dispatch the event
01288                                 }
01289                         }
01290                         else if (outputLevel>0) {
01291                                 FuseKitCommon.error('125',(_sID()));
01292                         }       
01293                 }
01294         }
01295 }

Generated on Fri May 11 17:12:43 2007 for GuggaFramework by  doxygen 1.5.2