duplicateSprite()
Top  Previous  Next


SWiSH Player Support
SWF4 or later - Supported Internally

Syntax
spritename.duplicateSprite(newname, depth)

Arguments
spritename: The target path of the Sprite / Movie Clip to duplicate.

newname: A unique identifier for the duplicated Sprite / Movie Clip.

depth: A unique depth level for the duplicated Sprite / Movie Clip. The depth level is a stacking order for duplicated sprites. This stacking order is much like the stacking order of layers in the Timeline; Sprites with a lower depth level are hidden under clips with a higher stacking order. You must assign each duplicated Sprite a unique depth level to prevent it from replacing Sprites of the same name on occupied depths.

Returns
Nothing.

Description
Method: Creates an Instance of a Sprite / Movie Clip while the Movie is playing. The playhead in duplicate Movie Clips always starts at Frame 1, regardless of where the playhead is in the original (or "parent") Movie Clip. Variables in the parent Movie Clip are not copied into the duplicate Movie Clip. If the parent Movie Clip is deleted, the duplicate Movie Clip is also deleted. Use the removeSprite() method to delete a Movie Clip Instance created with duplicateSprite() method.

Sample
This example duplicates the existing Sprite, s1, and creates a new Sprite s2 on the same level. The position of both Sprites is adjusted so that they can be seen. To remove the duplicated Sprite, use s2.removeSprite().

onLoad () {
    s1.duplicateSprite("s2",1);
    s1._X += 50;
    s1._Y += 50;
    s2._X += 150;
    s2._Y += 50;
}


See also
removeSprite and Sprite Methods
.