I've been trying to use
Senocular's duplicateDisplayObject() for a while and I've experienced a lot of crashes of specific versions of Flash player and also unsuccessful results when used within an AIR application. After playing around quite a bit with all this, the best way I've found is to avoid duplicating the instance but duplicate the element on the domain/library instead.
I'm pasting here a snippet of how it works:
/*
* node.@src example: file:///home/[username]/Desktop/[project]/files/assets/home/ball.swf
* Cache.get() its basically a Dictionary where I store all the externally loaded files using the url as keys
*/
var mc : DisplayObject = Cache.get( node.@src );
var pathArray : Array = String( node.@src ).split( "/" );
var filename : String = String( pathArray[ pathArray.length - 1 ] ).split( "." )[0];
if ( mc.loaderInfo.applicationDomain.hasDefinition( filename ))
mc = new ( mc.loaderInfo.applicationDomain.getDefinition( filename ))();
mc is now a clean duplication (as far as I know) of the original class. In my setup I expect the element that I want to be duplicated be named with the exact name as its container's filename (.swf), which is
perfect for FlexSDK compiled stuff, but need some teaching for Flash IDE.
This is, of course,
compatible with any kind of Object (not only MovieClips/Sprites/DisplayObjects)...