User Guide
856 ActionScript classes
initObject:Object [optional] - (Supported for Flash Player 6 and later.) An object that
contains properties with which to populate the duplicated movie clip. This parameter allows
dynamically created movie clips to receive clip parameters. If
initObject is not an object, it
is ignored. All properties of
initObject are copied into the new instance. The properties
specified with
initObject are available to the constructor function.
Returns
MovieClip - A reference to the duplicated movie clip (supported for Flash Player 6 and later).
Example
The following example duplicates a newly created MovieClip a number of times and traces
the target for each duplicate.
var container:MovieClip = setUpContainer();
var ln:Number = 10;
var spacer:Number = 1;
var duplicate:MovieClip;
for(var i:Number = 1; i < ln; i++) {
var newY:Number = i * (container._height + spacer);
duplicate = container.duplicateMovieClip("clip-" + i, i, {_y:newY});
trace(duplicate); // _level0.clip-[number]
}
function setUpContainer():MovieClip {
var mc:MovieClip = this.createEmptyMovieClip("container",
this.getNextHighestDepth());
var w:Number = 100;
var h:Number = 20;
mc.beginFill(0x333333);
mc.lineTo(w, 0);
mc.lineTo(w, h);
mc.lineTo(0, h);
mc.lineTo(0, 0);
mc.endFill();
return mc;
}
The MovieClip.getNextHighestDepth() method used in this example requires Flash Player
7 or later. If your SWF file includes a version 2 component, use the version 2 components
DepthManager class instead of the
MovieClip.getNextHighestDepth() method.
See also
loadMovie (MovieClip.loadMovie method), removeMovieClip
(MovieClip.removeMovieClip method)
, duplicateMovieClip function