克隆 flex 组件 [英] clone flex component

查看:41
本文介绍了克隆 flex 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行时复制 flex 组件.

I am trying to duplicate a flex component at run time.

例如,如果我有这个

mx:Button label="btn" id="btn" click="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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆