克隆flex组件 [英] clone flex component
问题描述
我想在运行时复制一个flex组件。
I am trying to duplicate a flex component at run time.
例如,如果我有这个
mx:Button label =btnid =btnclick =handleClick(event)/>
mx:Button label="btn" id="btn" click="handleClick(event)"/>
我应该能够调用一个名为DuplicateComponent ),它应该返回一个UI组件与上面的按钮包括事件监听器与它完全相同。
i should be able to call a function called DuplicateComponent() and it should return me a UI component thts exactly same as above button including the event listeners with it.
有人可以帮助我吗?
提前感谢
Can some one help me please?? Thanks in advance
推荐答案
执行字节数组复制。此代码段应该为您执行:
Do a Byte Array Copy. This code segment should do it for you:
// ActionScript file
import flash.utils.ByteArray;
private function clone(source:Object):*
{
var myBA:ByteArray = new ByteArray();
myBA.writeObject(source);
myBA.position = 0;
return(myBA.readObject());
}
一个注意,我没有自己写这个代码,我从Flex Coder列表中的一个帖子中获得了它。
One note, I did not write this code myself, I'm pretty sure I got it from a post on the Flex Coder's list.
这篇关于克隆flex组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!