<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="completeHandler()">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import flash.utils.ByteArray;
public function clone(source:Object):*
{
var myBA:ByteArray = new ByteArray();
myBA.writeObject(source);
myBA.position = 0;
return(myBA.readObject());
}
private var c1:CloneClass;
private var c2:Object;
private function completeHandler():void
{
c1 = new CloneClass();
c1.age = 30;
c1.button = new Button;
c1.button.label = "c1";
c2 = clone(c1);
trace("c1: " + c1.age + " " + c1.button.label); // 输出 c1: 30 c1
trace("c2: " + c2.age + " " + c2.button.label); // 输出 c2: 30 c1
}
private function change():void
{
c1.age = 50;
c1.button.label = "cc1";
trace("after changed --------------------------------");
trace("c1: " + c1.age + " " + c1.button.label); // 输出 c1: 50 cc1
trace("c2: " + c2.age + " " + c2.button.label); // 输出 c2: 30 c1
}
]]>
</mx:Script>
<mx:Button x="106" y="97" label="Change" click="change()"/>
</mx:Application>