克隆库 - 对象对Flash的复制? [英] Flash duplication of an Object - Cloning library?

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

问题描述

这可能是一个很简单的问题,我只是没有foggiest如何去做。

我有我要复制的对象,不知道该怎么去做。这里是我的尝试:

  VAR MyObj中=新的对象类();
VAR重复= MyObj中;
重复= NULL;
myObj.function(); //错误:空引用
 

对象类是非常大的,inherets并创建它自己的儿女,我敢肯定有大概几单班那里。

有没有一种方法可以轻松地复制的东西?

编辑:看起来像我在寻找克隆,因为其中有没有AS3功能,您apparantly不能反正克隆专用数据。任何人都知道的一个图书馆或解决方法cloneing一堆私人数据的?

解决方案

我从一些博客这个UTIL功能

,不能从那里,所以我不能给信贷记住。它不会与的BitmapData虽然工作。反正这里是:

 公共静态函数副本(O:对象):对象
{
VAR字节:的ByteArray =新的ByteArray();
bytes.writeObject(O);
bytes.position = 0;
返回bytes.readObject();
}
 

用法:
registerClassAlias​​(com.tests.TestClass,TestClass的); VAR testCopy:识别TestClass =识别TestClass(ObjectUtil.copy(测试));

This is probably a very simple question, I just don't have the foggiest how to go about it.

I have an Object that I want to duplicate, and don't know how to go about it. Here's my attempt:

var myObj = new ObjectClass();
var duplicate = myObj;
duplicate = null;
myObj.function(); // Error: Null reference

The ObjectClass is very large, inherets and creates children of it's own, and I'm sure there's probably a few singleton classes in there.

Is there a way to duplicate something easily?

Edit: Looks like I'm looking for "Cloning", for which there is no AS3 function, and you apparantly can't clone Private data anyway. Anyone know of a library or a workaround for cloneing a bunch of private data?

解决方案

I got this util function from some blog, can't remember from where so I can't give the credit. It wouldn't work with bitmapdata though. Anyway here it is:

public static function copy(o:Object):Object 
{
	var bytes:ByteArray = new ByteArray( );
	bytes.writeObject( o );
	bytes.position = 0;
	return bytes.readObject( );
}

Usage:
registerClassAlias("com.tests.TestClass", TestClass); var testCopy:TestClass = TestClass(ObjectUtil.copy(test));

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

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