AS3复制对象 [英] As3 Copy object

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

问题描述

有时我们需要克隆object.but如果一个DisplayObject有一些孩子,并使用该函数是这样的:

sometimes we need clone a object.but if a displayObject has some children and use the function like this:

function clone(source:*):*
{
    var b:ByteArray = new ByteArray();
    b.writeObject(source);
    b.position = 0;
    return(b.readObject());
}

但结果一直没有孩子.. ..。所以我应该怎么办?

but the result has no children.. .. . so what should I do ?

推荐答案

我没有编写一个克隆的方法我自己,但我发现,可能做的伎俩的方式。通过所有的变量迭代(在一个XML-RE presentation),你可以把它们复制在你的类的新实例。

I didn't have to program a clone-method myself yet, but i found a way that might do the trick. By iterating through all your variables (in an xml-representation), you can copy them in a new instance of your class.

您可以找到方法,我这个环节上谈到:的http://www.learnosity.com/techblog/index.cfm/2008/2/6/AS3--Looping-over-properties-of-a-class

you can find the method i am talking about on this link: http://www.learnosity.com/techblog/index.cfm/2008/2/6/AS3--Looping-over-properties-of-a-class

让我知道,如果它的工作原理,我有点好奇自己:)

Let me know if it works, i'm kind of curious myself :)

这篇关于AS3复制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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