O'Reilly logo

Flash 8 Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.9. Creating New Movie Clips Based on Existing Movie Clips

Problem

You want to create a duplicate movie clip instance based on an existing instance.

Solution

Use the duplicateMovieClip( ) method.

Discussion

With the duplicateMovieClip( ) method, you can quickly create duplicates of movie clip instances already on the stage. This method creates a copy of the movie clip instance from which it is invoked with a new instance name and depth:

	// Create a new movie clip named mNewInstance based on the movie clip named
	// originalInstance that already existed on the stage. The new movie clip is
	// created at depth 1.
	mOriginalInstance.duplicateMovieClip("mNewInstance", 1);

Tip

Make sure that you use a unique depth for the new movie clip. If you use a depth that corresponds to an existing instance, that existing instance will be overwritten.

Additionally, you can specify a third, optional parameter for the duplicateMovieClip( ) method. This parameter is known as the initialization object, and the properties and values of the initialization object are assigned to the new instance. The parameter value should be in the form of an ActionScript Object object, which you can create one of two ways:

  • Using the constructor and assigning properties and values via dot notation:

    	var oInitialization:Object = new Object();
    	oInitialization.property1 = "value1";
    	oInitialization. property2 = "value2;
  • Using the object literal notation:

    	var oInitialization:Object = { property1: "value1", property2: "value2"};

Both of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required