加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex动态获取Object的属性和值以及完成Object之间value的拷贝

发布时间:2020-12-15 03:53:33 所属栏目:百科 来源:网络整理
导读:1.如何动态获取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. 对象之
1.如何动态获取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:*) {
             ;
         }
     }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读