I have a movieclip that I need to duplicate dynamically based on an outside variable. e.g. clip1, clip2, etc This variable changes so I can't hardcode the number of times it occurs.
Is there a way to dynamically create this movieclip multiple times and align it according on the screen?
I wasn't able to find anything on Google..
Regards Luben
How about using a function that duplicates a DisplayObject. This function returns a new instance of the Class the provided object is:
function duplicateDisplayObject( dspObj:DisplayObject ):DisplayObject
{
var class_name:String = getQualifiedClassName( dspObj );
var definition:Class = getDefinitionByName( class_name ) as Class;
return new definition() as DisplayObject;
}
(MovieClip, Sprite, and Bitmap all inherit from DisplayObject)
Edit:
If you need to use it with MovieClips, you can simply:
var myDuplicate:MovieClip = duplicateDisplayObject( myOriginalMovieClip ) as MovieClip;