Table of Contents

MovieClip.createEmptyMovieClip( ) Method Flash 6

creates a new, empty MovieClip instance
mc.createEmptyMovieClip(instanceName, depth)

Arguments

instanceName

A string specifying the instance name of the clip to create. The name must adhere to the rules for creating an identifier outlined under Section 15.5. To enable code hinting in the Flash authoring tool, use clip instance names that include the suffix "_mc", as in ball_mc.

depth

An integer between -16384 and 1048575 (inclusive), specifying the level on which to place the new clip inside mc. Higher depths obscure lower depths, so a depth of 6 is in front of 5, which is in front of 4, and so on. Depths above -1 are reserved for dynamically generated content. Therefore, in most cases, you should use a depth between 0 and 1048575 with createEmptyMovieClip( ). However, when creating dynamic content that you want to appear beneath all author-time content in mc (e.g., a run-time background), use depth -16384. Depths from -16383 to -1 (inclusive) are reserved for author-time content and shouldn't be used with createEmptyMovieClip( ). For important details, see Section 13.4.

Returns

A reference to the new MovieClip instance.

Description

The createEmptyMovieClip( ) method creates a new, blank movie clip instance and attaches it to mc at the specified depth. If mc is the main movie, the new instance is placed in the top-left corner of the Stage. If mc is a movie clip instance, the new instance is placed at mc's registration point. The new instance is placed in mc's content stack at the specified depth, replacing any previous occupant of that depth.

The createEmptyMovieClip( ) method is used to create content at runtime without requiring any Library symbol. For example, to create a spaceship dynamically, we can create an empty clip and then use the MovieClip Drawing API methods to draw the ship. Likewise, to create a form or interface panel at runtime, we can create an empty clip and then populate it with text fields, as follows:

this.createEmptyMovieClip("form_mc", 1);
form_mc.createTextField("firstName_txt", 1, 0, 0, 200, 20);
form_mc.firstName_txt.border = true;
form_mc.firstName_txt.type = "input";
form_mc.createTextField("lastName_txt", 2, 0, 30, 200, 20);
form_mc.lastName_txt.border = true;
form_mc.lastName_txt.type = "input";
form_mc.createTextField("email_txt", 3, 0, 60, 200, 20);
form_mc.email_txt.border = true;
form_mc.email_txt.input = "input";

An empty movie clip can also be used simply as a holder for events, such as onEnterFrame( ), onKeyDown( ), onMouseDown( ), etc:

this.createEmptyMovieClip("process_mc", 1);
process_mc.onEnterFrame = function () {
  // perform per-frame tasks here
}

The createEmptyMovieClip( ) method returns a reference to the clip it creates. We can store this reference in a variable for easy access. For example, the following code creates an empty clip deeply nested inside an application's interface but stores a reference to the clip in the variable fileMenu:

// Create the clip.
var fileMenu = appPanels.editPanel.menuBar.createEmptyMovieClip
       ("fileMenu_mc", 1);
// Now manipulate the clip through the variable fileMenu.
fileMenu._x = 20;
fileMenu._y = 50;

A movie clip created with createEmptyMovieClip( ) can be used as a mask for other clips (see MovieClip.setMask( )) and can receive button events such as onPress( ) and onRelease( ). However, strokes and transparent fills are not recognized for masking or hit-testing for button events.

To delete a movie clip, use MovieClip.removeMovieClip( ). However, note that a movie clip placed on a negative depth cannot be removed via removeMovieClip( ). To remove a clip at a negative depth, first swap it to a positive depth, then remove it:

theClip_mc.swapDepths(1234);   // Pick a positive depth to swap to
theClip_mc.removeMovieClip();  // Remove the clip

See the removeMovieClip( ) global function Description for more important details.

Usage

Depths above 1048575 are partially functional but not supported. For example, though a movie clip can be attached to depth 1048576, it cannot be removed. An attempt to attach a movie clip to a depth below -16384 fails silently.

See Also

duplicateMovieClip( ), MovieClip.attachMovie( ), MovieClip.createTextField( ), MovieClip.duplicateMovieClip( ), MovieClip.getDepth( ), MovieClip.removeMovieClip( ), MovieClip.swapDepths( )


Table of Contents