home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / filler.swf / scripts / mx / binding / Binding.as next >
Text File  |  2008-09-02  |  5KB  |  168 lines

  1. package mx.binding
  2. {
  3.    import mx.collections.errors.ItemPendingError;
  4.    import mx.core.mx_internal;
  5.    
  6.    use namespace mx_internal;
  7.    
  8.    public class Binding
  9.    {
  10.       
  11.       mx_internal static const VERSION:String = "2.0.1.0";
  12.        
  13.       
  14.       mx_internal var destFunc:Function;
  15.       
  16.       mx_internal var srcFunc:Function;
  17.       
  18.       mx_internal var destString:String;
  19.       
  20.       mx_internal var document:Object;
  21.       
  22.       private var hasHadValue:Boolean;
  23.       
  24.       mx_internal var isExecuting:Boolean;
  25.       
  26.       mx_internal var isHandlingEvent:Boolean;
  27.       
  28.       public var twoWayCounterpart:Binding;
  29.       
  30.       private var wrappedFunctionSuccessful:Boolean;
  31.       
  32.       public var uiComponentWatcher:int;
  33.       
  34.       private var lastValue:Object;
  35.       
  36.       public function Binding(param1:Object, param2:Function, param3:Function, param4:String)
  37.       {
  38.          super();
  39.          this.document = param1;
  40.          this.srcFunc = param2;
  41.          this.destFunc = param3;
  42.          this.destString = param4;
  43.          isExecuting = false;
  44.          isHandlingEvent = false;
  45.          hasHadValue = false;
  46.          uiComponentWatcher = -1;
  47.          BindingManager.addBinding(param1,param4,this);
  48.       }
  49.       
  50.       public function watcherFired(param1:Boolean, param2:int) : void
  51.       {
  52.          var commitEvent:Boolean = param1;
  53.          var cloneIndex:int = param2;
  54.          if(mx_internal::isHandlingEvent)
  55.          {
  56.             return;
  57.          }
  58.          try
  59.          {
  60.             isHandlingEvent = true;
  61.             execute(cloneIndex);
  62.          }
  63.          finally
  64.          {
  65.             isHandlingEvent = false;
  66.          }
  67.       }
  68.       
  69.       protected function wrapFunctionCall(param1:Object, param2:Function, param3:Object = null, ... rest) : Object
  70.       {
  71.          var result:Object = null;
  72.          var thisArg:Object = param1;
  73.          var wrappedFunction:Function = param2;
  74.          var object:Object = param3;
  75.          var args:Array = rest;
  76.          wrappedFunctionSuccessful = false;
  77.          try
  78.          {
  79.             result = wrappedFunction.apply(thisArg,args);
  80.             wrappedFunctionSuccessful = true;
  81.             return result;
  82.          }
  83.          catch(itemPendingError:ItemPendingError)
  84.          {
  85.             itemPendingError.addResponder(new EvalBindingResponder(this,object));
  86.             if(BindingManager.debugDestinationStrings[mx_internal::destString])
  87.             {
  88.                trace("Binding: destString = " + mx_internal::destString + ", error = " + itemPendingError);
  89.             }
  90.          }
  91.          catch(rangeError:RangeError)
  92.          {
  93.             if(BindingManager.debugDestinationStrings[mx_internal::destString])
  94.             {
  95.                trace("Binding: destString = " + mx_internal::destString + ", error = " + rangeError);
  96.             }
  97.          }
  98.          catch(error:Error)
  99.          {
  100.             if(error.errorID != 1006 && error.errorID != 1009 && error.errorID != 1010 && error.errorID != 1055 && error.errorID != 1069)
  101.             {
  102.                throw error;
  103.             }
  104.             if(BindingManager.debugDestinationStrings[mx_internal::destString])
  105.             {
  106.                trace("Binding: destString = " + mx_internal::destString + ", error = " + error);
  107.             }
  108.          }
  109.          return null;
  110.       }
  111.       
  112.       public function execute(param1:Object = null) : void
  113.       {
  114.          var o:Object = param1;
  115.          if(mx_internal::isExecuting || twoWayCounterpart && twoWayCounterpart.isExecuting)
  116.          {
  117.             hasHadValue = true;
  118.             return;
  119.          }
  120.          try
  121.          {
  122.             isExecuting = true;
  123.             wrapFunctionCall(this,innerExecute,o);
  124.          }
  125.          finally
  126.          {
  127.             isExecuting = false;
  128.          }
  129.       }
  130.       
  131.       private function nodeSeqEqual(param1:XMLList, param2:XMLList) : Boolean
  132.       {
  133.          var _loc3_:uint = 0;
  134.          var _loc4_:uint = 0;
  135.          _loc3_ = param1.length();
  136.          if(_loc3_ == param2.length())
  137.          {
  138.             _loc4_ = 0;
  139.             while(_loc4_ < _loc3_ && param1[_loc4_] === param2[_loc4_])
  140.             {
  141.                _loc4_++;
  142.             }
  143.             return _loc4_ == _loc3_;
  144.          }
  145.          return false;
  146.       }
  147.       
  148.       private function innerExecute() : void
  149.       {
  150.          var _loc1_:Object = null;
  151.          _loc1_ = wrapFunctionCall(mx_internal::document,mx_internal::srcFunc);
  152.          if(BindingManager.debugDestinationStrings[mx_internal::destString])
  153.          {
  154.             trace("Binding: destString = " + mx_internal::destString + ", srcFunc result = " + _loc1_);
  155.          }
  156.          if(hasHadValue || wrappedFunctionSuccessful)
  157.          {
  158.             if(!(lastValue is XML && lastValue.hasComplexContent() && lastValue === _loc1_) && !(lastValue is XMLList && lastValue.hasComplexContent() && _loc1_ is XMLList && nodeSeqEqual(lastValue as XMLList,_loc1_ as XMLList)))
  159.             {
  160.                mx_internal::destFunc.call(mx_internal::document,_loc1_);
  161.                lastValue = _loc1_;
  162.                hasHadValue = true;
  163.             }
  164.          }
  165.       }
  166.    }
  167. }
  168.