flash 引用与复制(ByteArray的拷贝方法)

作者:袖梨 2022-07-02

import flash.utils.ByteArray;

var myObj1:Object = new Object();
myObj1.nu = 10;
myObj1.nu2 = 16;

var myObj2:Object = new Object();
myObj2 = clone(myObj1);
myObj2.nu = 100;
myObj2.nu2 = 18;

trace("myObj2.nu: " + myObj2.nu);
trace("myObj2.nu2: " + myObj2.nu2);
trace("myObj1.nu: " + myObj1.nu);
trace("myObj1.nu2: " + myObj1.nu2);

function clone(obj:Object):* {
 var myBA:ByteArray = new ByteArray();
 myBA.writeObject(obj);
 myBA.position = 0;
 return (myBA.readObject());

}

相关文章

精彩推荐