当前位置:软件学习 > Flash >>

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

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());

}

补充:flash教程,Action
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,