home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2012 April / ME_04_2012.iso / Video-Tutorial / iPhoto / media / player.swf / scripts / mx / utils / ObjectProxy.as < prev    next >
Encoding:
Text File  |  2011-11-11  |  8.0 KB  |  265 lines

  1. package mx.utils
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.EventDispatcher;
  5.    import flash.utils.IDataInput;
  6.    import flash.utils.IDataOutput;
  7.    import flash.utils.IExternalizable;
  8.    import flash.utils.Proxy;
  9.    import flash.utils.flash_proxy;
  10.    import flash.utils.getQualifiedClassName;
  11.    import mx.core.IPropertyChangeNotifier;
  12.    import mx.events.PropertyChangeEvent;
  13.    import mx.events.PropertyChangeEventKind;
  14.    
  15.    use namespace object_proxy;
  16.    use namespace flash_proxy;
  17.    
  18.    [Bindable("propertyChange")]
  19.    public dynamic class ObjectProxy extends Proxy implements IExternalizable, IPropertyChangeNotifier
  20.    {
  21.       protected var dispatcher:EventDispatcher;
  22.       
  23.       protected var notifiers:Object;
  24.       
  25.       protected var proxyClass:Class = ObjectProxy;
  26.       
  27.       protected var propertyList:Array;
  28.       
  29.       private var _proxyLevel:int;
  30.       
  31.       private var _item:Object;
  32.       
  33.       private var _type:QName;
  34.       
  35.       private var _id:String;
  36.       
  37.       public function ObjectProxy(param1:Object = null, param2:String = null, param3:int = -1)
  38.       {
  39.          super();
  40.          if(!param1)
  41.          {
  42.             param1 = {};
  43.          }
  44.          this._item = param1;
  45.          this._proxyLevel = param3;
  46.          this.notifiers = {};
  47.          this.dispatcher = new EventDispatcher(this);
  48.          if(param2)
  49.          {
  50.             this._id = param2;
  51.          }
  52.       }
  53.       
  54.       object_proxy function get object() : Object
  55.       {
  56.          return this._item;
  57.       }
  58.       
  59.       object_proxy function get type() : QName
  60.       {
  61.          return this._type;
  62.       }
  63.       
  64.       object_proxy function set type(param1:QName) : void
  65.       {
  66.          this._type = param1;
  67.       }
  68.       
  69.       public function get uid() : String
  70.       {
  71.          if(this._id === null)
  72.          {
  73.             this._id = UIDUtil.createUID();
  74.          }
  75.          return this._id;
  76.       }
  77.       
  78.       public function set uid(param1:String) : void
  79.       {
  80.          this._id = param1;
  81.       }
  82.       
  83.       override flash_proxy function getProperty(param1:*) : *
  84.       {
  85.          var _loc2_:* = undefined;
  86.          if(this.notifiers[param1.toString()])
  87.          {
  88.             return this.notifiers[param1];
  89.          }
  90.          _loc2_ = this._item[param1];
  91.          if(_loc2_)
  92.          {
  93.             if(this._proxyLevel == 0 || ObjectUtil.isSimple(_loc2_))
  94.             {
  95.                return _loc2_;
  96.             }
  97.             _loc2_ = this.object_proxy::getComplexProperty(param1,_loc2_);
  98.          }
  99.          return _loc2_;
  100.       }
  101.       
  102.       override flash_proxy function callProperty(param1:*, ... rest) : *
  103.       {
  104.          return this._item[param1].apply(this._item,rest);
  105.       }
  106.       
  107.       override flash_proxy function deleteProperty(param1:*) : Boolean
  108.       {
  109.          var _loc5_:PropertyChangeEvent = null;
  110.          var _loc2_:IPropertyChangeNotifier = IPropertyChangeNotifier(this.notifiers[param1]);
  111.          if(_loc2_)
  112.          {
  113.             _loc2_.removeEventListener(PropertyChangeEvent.PROPERTY_CHANGE,this.propertyChangeHandler);
  114.             delete this.notifiers[param1];
  115.          }
  116.          var _loc3_:* = this._item[param1];
  117.          var _loc4_:* = delete this._item[param1];
  118.          if(this.dispatcher.hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
  119.          {
  120.             _loc5_ = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE);
  121.             _loc5_.kind = PropertyChangeEventKind.DELETE;
  122.             _loc5_.property = param1;
  123.             _loc5_.oldValue = _loc3_;
  124.             _loc5_.source = this;
  125.             this.dispatcher.dispatchEvent(_loc5_);
  126.          }
  127.          return _loc4_;
  128.       }
  129.       
  130.       override flash_proxy function hasProperty(param1:*) : Boolean
  131.       {
  132.          return param1 in this._item;
  133.       }
  134.       
  135.       override flash_proxy function nextName(param1:int) : String
  136.       {
  137.          return this.propertyList[param1 - 1];
  138.       }
  139.       
  140.       override flash_proxy function nextNameIndex(param1:int) : int
  141.       {
  142.          if(param1 == 0)
  143.          {
  144.             this.setupPropertyList();
  145.          }
  146.          if(param1 < this.propertyList.length)
  147.          {
  148.             return param1 + 1;
  149.          }
  150.          return 0;
  151.       }
  152.       
  153.       override flash_proxy function nextValue(param1:int) : *
  154.       {
  155.          return this._item[this.propertyList[param1 - 1]];
  156.       }
  157.       
  158.       override flash_proxy function setProperty(param1:*, param2:*) : void
  159.       {
  160.          var _loc4_:IPropertyChangeNotifier = null;
  161.          var _loc5_:PropertyChangeEvent = null;
  162.          var _loc3_:* = this._item[param1];
  163.          if(_loc3_ !== param2)
  164.          {
  165.             this._item[param1] = param2;
  166.             _loc4_ = IPropertyChangeNotifier(this.notifiers[param1]);
  167.             if(_loc4_)
  168.             {
  169.                _loc4_.removeEventListener(PropertyChangeEvent.PROPERTY_CHANGE,this.propertyChangeHandler);
  170.                delete this.notifiers[param1];
  171.             }
  172.             if(this.dispatcher.hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
  173.             {
  174.                if(param1 is QName)
  175.                {
  176.                   param1 = QName(param1).localName;
  177.                }
  178.                _loc5_ = PropertyChangeEvent.createUpdateEvent(this,param1.toString(),_loc3_,param2);
  179.                this.dispatcher.dispatchEvent(_loc5_);
  180.             }
  181.          }
  182.       }
  183.       
  184.       object_proxy function getComplexProperty(param1:*, param2:*) : *
  185.       {
  186.          if(param2 is IPropertyChangeNotifier)
  187.          {
  188.             param2.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,this.propertyChangeHandler);
  189.             this.notifiers[param1] = param2;
  190.             return param2;
  191.          }
  192.          if(getQualifiedClassName(param2) == "Object")
  193.          {
  194.             param2 = new this.proxyClass(this._item[param1],null,this._proxyLevel > 0 ? this._proxyLevel - 1 : this._proxyLevel);
  195.             param2.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,this.propertyChangeHandler);
  196.             this.notifiers[param1] = param2;
  197.             return param2;
  198.          }
  199.          return param2;
  200.       }
  201.       
  202.       public function readExternal(param1:IDataInput) : void
  203.       {
  204.          var _loc2_:Object = param1.readObject();
  205.          this._item = _loc2_;
  206.       }
  207.       
  208.       public function writeExternal(param1:IDataOutput) : void
  209.       {
  210.          param1.writeObject(this._item);
  211.       }
  212.       
  213.       public function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
  214.       {
  215.          this.dispatcher.addEventListener(param1,param2,param3,param4,param5);
  216.       }
  217.       
  218.       public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
  219.       {
  220.          this.dispatcher.removeEventListener(param1,param2,param3);
  221.       }
  222.       
  223.       public function dispatchEvent(param1:Event) : Boolean
  224.       {
  225.          return this.dispatcher.dispatchEvent(param1);
  226.       }
  227.       
  228.       public function hasEventListener(param1:String) : Boolean
  229.       {
  230.          return this.dispatcher.hasEventListener(param1);
  231.       }
  232.       
  233.       public function willTrigger(param1:String) : Boolean
  234.       {
  235.          return this.dispatcher.willTrigger(param1);
  236.       }
  237.       
  238.       public function propertyChangeHandler(param1:PropertyChangeEvent) : void
  239.       {
  240.          this.dispatcher.dispatchEvent(param1);
  241.       }
  242.       
  243.       protected function setupPropertyList() : void
  244.       {
  245.          var _loc1_:String = null;
  246.          if(getQualifiedClassName(this._item) == "Object")
  247.          {
  248.             this.propertyList = [];
  249.             for(_loc1_ in this._item)
  250.             {
  251.                this.propertyList.push(_loc1_);
  252.             }
  253.          }
  254.          else
  255.          {
  256.             this.propertyList = ObjectUtil.getClassInfo(this._item,null,{
  257.                "includeReadOnly":true,
  258.                "uris":["*"]
  259.             }).properties;
  260.          }
  261.       }
  262.    }
  263. }
  264.  
  265.