Duplicate Object in AS3

Well this snippet does not copy the whole object, but you can create a new instance of that object.

function createNewInstance(obj : *) : *
{
	var ClassReference:Class;
	ClassReference = getDefinitionByName(
				getQualifiedClassName(obj)
				) as Class;
	return new ClassReference();
}
 
// demo
 
var tmp : MyType = new myType();
var tmp2 : MyType = createNewInstance(tmp);

 

Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">