home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 148 / MOBICLIC148.ISO / mac / DATA / DSS148 / DSS148_01 / DSS148_01.swf / scripts / dss148_01 / ObjectInitializer.as < prev   
Text File  |  2012-10-16  |  4KB  |  123 lines

  1. package dss148_01
  2. {
  3.    public class ObjectInitializer
  4.    {
  5.        
  6.       
  7.       private var _instance = null;
  8.       
  9.       private var _object = null;
  10.       
  11.       private var _initObject = null;
  12.       
  13.       public function ObjectInitializer(param1:*, param2:Object, param3:* = null)
  14.       {
  15.          super();
  16.          this._instance = param1;
  17.          this._object = param2;
  18.          this._initObject = param3;
  19.          this.initialize();
  20.       }
  21.       
  22.       private function destroy() : void
  23.       {
  24.          this._instance = null;
  25.          this._object = null;
  26.          this._initObject = null;
  27.       }
  28.       
  29.       private function initialize() : void
  30.       {
  31.          if(this._initObject == null)
  32.          {
  33.             this.destroy();
  34.             return;
  35.          }
  36.          if(this._initObject is XML)
  37.          {
  38.             this.fromXML(this._initObject);
  39.             this.destroy();
  40.          }
  41.          else if(this._initObject is XMLList)
  42.          {
  43.             this.fromXML(this._initObject[0]);
  44.             this.destroy();
  45.          }
  46.          else if(this._initObject is Object)
  47.          {
  48.             this.fromObject(this._initObject);
  49.             this.destroy();
  50.          }
  51.       }
  52.       
  53.       private function fromObject(param1:*) : void
  54.       {
  55.          var _loc2_:* = null;
  56.          for(_loc2_ in param1 as Object)
  57.          {
  58.             this._object[_loc2_] = param1[_loc2_];
  59.          }
  60.       }
  61.       
  62.       private function fromXML(param1:XML) : void
  63.       {
  64.          var _loc2_:String = null;
  65.          var _loc4_:XML = null;
  66.          var _loc5_:String = null;
  67.          var _loc3_:XMLList = param1.Param;
  68.          for each(_loc4_ in _loc3_)
  69.          {
  70.             if(_loc4_.hasOwnProperty("@type"))
  71.             {
  72.                _loc2_ = String(_loc4_.@type);
  73.             }
  74.             else if(this._instance[_loc4_.@nom] !== undefined)
  75.             {
  76.                if(this._instance[_loc4_.@nom] is Boolean)
  77.                {
  78.                   _loc2_ = "boolean";
  79.                }
  80.                else if(this._instance[_loc4_.@nom] is Number)
  81.                {
  82.                   _loc2_ = "number";
  83.                }
  84.                else if(this._instance[_loc4_.@nom] is int)
  85.                {
  86.                   _loc2_ = "int";
  87.                }
  88.                else if(this._instance[_loc4_.@nom] is String)
  89.                {
  90.                   _loc2_ = "string";
  91.                }
  92.                else if(this._instance[_loc4_.@nom] is Array)
  93.                {
  94.                   _loc2_ = "array";
  95.                }
  96.             }
  97.             else
  98.             {
  99.                _loc2_ = "string";
  100.             }
  101.             switch(_loc2_)
  102.             {
  103.                case "boolean":
  104.                   this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = String(_loc4_.@valeur) == "true" ? true : false;
  105.                   break;
  106.                case "number":
  107.                   this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = Number(_loc4_.@valeur);
  108.                   break;
  109.                case "int":
  110.                   this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = int(_loc4_.@valeur);
  111.                   break;
  112.                case "array":
  113.                   this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = String(_loc4_.@valeur).split(",");
  114.                   break;
  115.                case "string":
  116.                   this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = String(_loc4_.@valeur);
  117.                   break;
  118.             }
  119.          }
  120.       }
  121.    }
  122. }
  123.