View comments | RSS feed

duplicateMovieClip function

duplicateMovieClip(target:String, newname:String, depth:Number) : Void
duplicateMovieClip(target:MovieClip, newname:String, depth:Number) : Void

Creates an instance of a movie clip while the SWF file is playing. The playhead in duplicate movie clips always starts at Frame 1, regardless of where the playhead is in the original movie clip. Variables in the original movie clip are not copied into the duplicate movie clip. Use the removeMovieClip() function or method to delete a movie clip instance created with duplicateMovieClip().

Availability: ActionScript 1.0; Flash Player 4

Parameters

target:Object - The target path of the movie clip to duplicate. This parameter can be either a String (e.g. "my_mc") or a direct reference to the movie clip instance (e.g. my_mc). Parameters that can accept more than one data type are listed as type Object.

newname:String - A unique identifier for the duplicated movie clip.

depth:Number - A unique depth level for the duplicated movie clip. The depth level is a stacking order for duplicated movie clips. This stacking order is similar to the stacking order of layers in the Timeline; movie clips with a lower depth level are hidden under clips with a higher stacking order. You must assign each duplicated movie clip a unique depth level to prevent it from replacing SWF files on occupied depths.

Example

In the following example, a new movie clip instance is created called img_mc. An image is loaded into the movie clip, and then the img_mc clip is duplicated. The duplicated clip is called newImg_mc, and this new clip is moved on the Stage so it does not overlap the original clip, and the same image is loaded into the second clip.

this.createEmptyMovieClip("img_mc", this.getNextHighestDepth());
img_mc.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");
duplicateMovieClip(img_mc, "newImg_mc", this.getNextHighestDepth());
newImg_mc._x = 200;
newImg_mc.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");

To remove the duplicate movie clip, you could add this code for a button called myButton_btn.

this.myButton_btn.onRelease = function(){
 removeMovieClip(newImg_mc);
};

See also

removeMovieClip function, duplicateMovieClip (MovieClip.duplicateMovieClip method), removeMovieClip (MovieClip.removeMovieClip method)


Version 8

Comments


No screen name said on Jan 27, 2006 at 1:42 PM :
Its unclear from this doc whether it's possible to have the new clip have a different parent MovieClip than the one being duplicated. This would be very useful for dragging a duplicate of a masked clip, and having the duplicate not be masked, for instance.
gibbitz said on Dec 4, 2006 at 9:35 AM :
ditto.
I'm in a situation where I need a rotate widget attached to a dragable movieclip. This clip is created with duplicateMovieClip and is one of 50 movieclips so using attachMovieClip with linkage is out of the question due to pre-frame 1 load times. I want to duplicate this movie into a parent that also contains the rotate widget so I can move mouse events away from the parent clip. As it stands, I will be using a work around, again.
juankpro said on Aug 1, 2007 at 7:48 AM :
MovieClips can not be re parented and the same happens with duplicateMovieClip, they cannot be created into another movieClip. To do that use attachMovie. If you don't want the movies to load before the first frame, deactivate the Export on first frame option on the Linkage dialog and place the movieclips in a preloading frame so you can load them with a loading bar or any other technique.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001724.html