<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.4" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: AS3 DeepCopy Utility Class</title>
	<link>http://www.ericfeminella.com/blog/2006/08/17/actionscript-2-deepclone-utility-class/</link>
	<description></description>
	<pubDate>Tue, 06 Jan 2009 11:51:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>

	<item>
		<title>by: eric</title>
		<link>http://www.ericfeminella.com/blog/2006/08/17/actionscript-2-deepclone-utility-class/#comment-3492</link>
		<pubDate>Thu, 23 Aug 2007 05:22:18 +0000</pubDate>
		<guid>http://www.ericfeminella.com/blog/2006/08/17/actionscript-2-deepclone-utility-class/#comment-3492</guid>
					<description>Yes, this will only deep copy a native object. In order to cast a class object you will need to call registerClassAlias(...); and then type cast the object.

You can do so as in the following:

package {

import flash.net.registerClassAlias;
import mx.utils.ObjectUtil;

public final class DeepCopy {
public static function clone(instance:Object, alias:String, Type:Class) : * {
registerClassAlias( alias, Type );
return Type(ObjectUtil.copy( instance )) ;
}
}
}

Keep in mind if the Class constructor takes any arguments this will not work as you will get a #1063 RTE: Argument count mismatch... You will need to create your own deserialization API to handle constructor arguments as cloning an object will create a new instance which matches that of the cloned instance thus calling new on the Class object.

I will update the DeepCopy class to implement the above method.</description>
		<content:encoded><![CDATA[<p>Yes, this will only deep copy a native object. In order to cast a class object you will need to call registerClassAlias(&#8230;); and then type cast the object.</p>
<p>You can do so as in the following:</p>
<p>package {</p>
<p>import flash.net.registerClassAlias;<br />
import mx.utils.ObjectUtil;</p>
<p>public final class DeepCopy {<br />
public static function clone(instance:Object, alias:String, Type:Class) : * {<br />
registerClassAlias( alias, Type );<br />
return Type(ObjectUtil.copy( instance )) ;<br />
}<br />
}<br />
}</p>
<p>Keep in mind if the Class constructor takes any arguments this will not work as you will get a #1063 RTE: Argument count mismatch&#8230; You will need to create your own deserialization API to handle constructor arguments as cloning an object will create a new instance which matches that of the cloned instance thus calling new on the Class object.</p>
<p>I will update the DeepCopy class to implement the above method.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: DesertFox07</title>
		<link>http://www.ericfeminella.com/blog/2006/08/17/actionscript-2-deepclone-utility-class/#comment-3490</link>
		<pubDate>Wed, 22 Aug 2007 19:33:04 +0000</pubDate>
		<guid>http://www.ericfeminella.com/blog/2006/08/17/actionscript-2-deepclone-utility-class/#comment-3490</guid>
					<description>I also get this same error. How do you avoid this error?</description>
		<content:encoded><![CDATA[<p>I also get this same error. How do you avoid this error?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: sxm20</title>
		<link>http://www.ericfeminella.com/blog/2006/08/17/actionscript-2-deepclone-utility-class/#comment-3443</link>
		<pubDate>Thu, 26 Jul 2007 02:18:49 +0000</pubDate>
		<guid>http://www.ericfeminella.com/blog/2006/08/17/actionscript-2-deepclone-utility-class/#comment-3443</guid>
					<description>I get 
Type Coercion failed: cannot convert Object@22c8ca61 to com.thed.utils.HashMap

when I try to cast the cloned object back. Any idea?</description>
		<content:encoded><![CDATA[<p>I get<br />
Type Coercion failed: cannot convert <a href="mailto:Object@22c8ca61">Object@22c8ca61</a> to com.thed.utils.HashMap</p>
<p>when I try to cast the cloned object back. Any idea?
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
