View comments | RSS feed

MovieClip.duplicateMovieClip()

Availability

Flash Player 5.

Usage

my_mc.duplicateMovieClip(newname:String, depth:Number [,initObject:Object]) : MovieClip

Parameters

newname A unique identifier for the duplicate movie clip.

depth A unique number specifying the depth at which the SWF file specified is to be placed.

initObject (Supported for Flash Player 6 and later.) An object containing 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. This parameter is optional.

Returns

A reference to the duplicated movie clip.

Description

Method; creates an instance of the specified movie clip while the SWF file is playing. Duplicated movie clips always start playing at Frame 1, no matter what frame the original movie clip is on when the duplicateMovieClip() method is called. Variables in the parent movie clip are not copied into the duplicate movie clip. Movie clips that have been created using duplicateMovieClip() are not duplicated if you call duplicateMovieClip() on their parent. If the parent movie clip is deleted, the duplicate movie clip is also deleted. If you have loaded a movie clip using MovieClip.loadMovie() or the MovieClipLoader class, the contents of the SWF file are not duplicated. This means that you cannot save bandwidth by loading a JPEG or SWF file and then duplicating the movie clip.

Example

The following example duplicates the circle_mc movie clip. The code creates the movie clip, called circle1_mc, at the x, y coordinates 20,20.

circle_mc.duplicateMovieClip("circle1_mc", this.getNextHighestDepth(), {_x:20, _y:20});

See also

duplicateMovieClip(), MovieClip.removeMovieClip()

Comments


Fumio Nonaka said on Dec 5, 2004 at 2:06 AM :
The returned reference of the duplicated MovieClip instance should be
supported for Flash Player 6 and later.
No screen name said on Dec 9, 2004 at 8:26 AM :
It would be better if a jpg image (or swf) could be duplicated like every other movie. It doesn't make sense to load same file couple of times if you want it on stage in more copies.
Neeil said on Jan 19, 2005 at 9:12 AM :
" ... you cannot save bandwidth by loading a JPEG or SWF file and then duplicating the movie clip."

- true, however loading the same image multiple times is quicker after the first time because the file is usually cached by the browser.
nintybloke said on May 18, 2005 at 4:39 AM :
" ...It doesn't make sense to load same file couple of times if you want it on stage in more copies."

- It does when you're making games (like say a shooter, then you need to dynamically make duplicates for enmeies and/or bullets...
Fumio Nonaka said on Jun 12, 2005 at 12:03 AM :
[Parameters]
Incorrect: "depth A unique number specifying the depth at which the
SWF file specified is to be placed".

Correct: "depth A unique number specifying the depth at which the
MovieClip specified is to be placed".
sstringer said on Jul 6, 2005 at 5:18 PM :
" true, however loading the same image multiple times is quicker after the first time because the file is usually cached by the browser."

True, but this still isn't a usable solution. Reloading still produces a very visible flash or blink.

It is simply imperative that we be able to duplicate dynamically loaded images and swfs (that is, external files that are loaded into the source clip via loadMovie() or MovieClipLoader.loadClip() ) without having to reload the image/swf into the new clip. Based on the astounding number of threads on this specific topic, I'd say the need is clear: MM needs to step up and correct this major flaw.
WebDuG said on Jul 15, 2005 at 12:57 PM :
I am the seniior software engineer at D-Tools, Inc using Flash MX-2004 and OOP. I work with dynamically created movieClips frequently. I have developed what we call "smartShapes", which are dynamically created movieClips with multiple "child" MovieClips nested within. The child MCs each have complex positioning and sizing formulas that basically keep the shape looking good as the main (parent) shape is stretched horizontally or vertically. This all works find and good. My problem comes about when I need to copy one or more of these smartShapes at run-time. I have to recreate the shape from scratch, applying all the EXACT same sizing and positioning formulas. My application allows selecting and copying multiple shapes at once. This brings my application to it's knees (slows it down miserably) if there are many smartShapes involved. It is unacceptable that I have to go through this recreation process as it takes prohibitive amounts of CPU time. We developers need a way to access dynamically created symbols with complex contents as any other symbol. So If my dynamic symbol requires work (CPU time) to create, I should be able to reference this as I do a symbol created at author time, given an identifier and exported for action script. Also I should be able to use a symol with a JPEG loaded into it several times on any _level, and NOT have to reload the JPEG. Any suggestions? I've been wrestling with this for years now expecting this glaring short-coming to be addressed/fixed. I have spear-headed using Flash for our application and we are deep in development, but user-experience is KEY, and this doesn't look good to our users.
flashteacher.ca said on Jul 18, 2005 at 2:09 PM :
the 'duplicateMovieClip' method should duplicate a movie dynamically loaded using 'loadMovie'.
petevenkman said on Aug 15, 2005 at 5:03 PM :
it SHOULD. is there no way to do it?
Pimpelsang said on Oct 5, 2005 at 7:43 AM :
Yes, I've run into same issue as most of you. Flick in reloading jpg is unacceptable solution :(
ChrisDola said on Nov 8, 2005 at 7:39 AM :
duplicateMovieClip() does not seem to work on Video instances (i.e. Embedded Video dragged to the stage)

 

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

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001496.html