Flex動態(tài)獲取Object的屬性和值以及完成Object之間value的拷貝

          1.如何動態(tài)獲取Object中的屬性和值
          var ct:CustomObject=newCustomObject(); 
          var xml:XML = describeType(ct);
          for each(var accessor in xml..accessor){
            
          var name:String= accessor.@name;
            
          var type:String= accessor.@type;
            trace(ct[name]);
          }

          2. 對象之間的拷貝
          /**
           * copies a source object to a destination object
           * @param sourceObject the source object
           * @param destinationObject the destination object
           *
           
          */
          public static 
          function copyObject(sourceObject:Object, destinationObject:Object):void
          {
              
          // check if the objects are not null
              if((sourceObject) && (destinationObject)) {
                  
          try
                  {
                      
          //retrive information about the source object via XML
                      var sourceInfo:XML = describeType(sourceObject);
                      
          var objectProperty:XML;
                      
          var propertyName:String;

                      
          // loop through the properties
                      for each(objectProperty in sourceInfo.variable)
                      {
                          propertyName 
          = objectProperty.@name;
                          
          if(sourceObject[objectProperty.@name] != null)
                          {
                              
          if(destinationObject.hasOwnProperty(objectProperty.@name)) {
                                  destinationObject[objectProperty.@name] 
          = sourceObject[objectProperty.@name];
                              }
                          }
                      }
                      
          //loop through the accessors
                      for each(objectProperty in sourceInfo.accessor) {
                          
          if(objectProperty.@access == "readwrite") {
                              propertyName 
          = objectProperty.@name;
                              
          if(sourceObject[objectProperty.@name] != null)
                              {
                                  
          if(destinationObject.hasOwnProperty(objectProperty.@name)) {
                                      destinationObject[objectProperty.@name] 
          = sourceObject[objectProperty.@name];
                                  }
                              }
                          }
                      }
                  }
                  
          catch (err:*) {
                      ;
                  }
              }



          posted on 2010-08-25 13:55 想飛就飛 閱讀(5102) 評論(0)  編輯  收藏 所屬分類: Flex

          公告


          導航

          <2010年8月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          統(tǒng)計

          常用鏈接

          留言簿(13)

          我參與的團隊

          隨筆分類(69)

          隨筆檔案(68)

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南川市| 垣曲县| 靖安县| 天气| 南漳县| 襄垣县| 罗田县| 大渡口区| 台南市| 绍兴县| 饶阳县| 昌江| 淳化县| 通山县| 海淀区| 长阳| 衡东县| 建湖县| 大宁县| 浏阳市| 铅山县| 横山县| 上栗县| 陕西省| 舒城县| 遂宁市| 锡林浩特市| 凉城县| 英德市| 曲水县| 康保县| 青阳县| 柳江县| 边坝县| 千阳县| 六枝特区| 吴旗县| 成都市| 雅安市| 谷城县| 长宁区|