AS3 對象之間拷貝BaseCopyObject 類

import mx.utils.ObjectUtil;

 /**
  * Author:luodongfu
  * Data:2012
  */
 public class BaseCopyObject
 {
  /**
   * 拷貝source的值到targetObj對象中
   * 包括:set get 函數以及其他屬性,和其父類屬性 set get函數
   */
  public function copyObjectAll(source:Object):void
  {
   var info:Object = ObjectUtil.getClassInfo(source);
   var props:Array = info["properties"]; 
   for each(var qn:QName in props)
   {
    if(this.hasOwnProperty(qn.localName))
     this[qn.localName] = source[qn.localName];
   }
   
  }
  
  
  /**
   * 拷貝source的值到targetObj對象中
   * 包括:其他屬性不包括本身以及父類set get對象屬性
   */
  public function copyObjectPropertis(source:Object):void
  {
   for (var property:String in source)
   {
    if (this.hasOwnProperty(propertyp))
     this[property] = source[property];
   }
  }

 

  }
 }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章