View comments | RSS feed

MovieClip.createEmptyMovieClip()

Availability

Flash Player 6.

Usage

my_mc.createEmptyMovieClip(instanceName:String, depth:Number) : MovieClip

Parameters

instanceName A string that identifies the instance name of the new movie clip.

depth An integer that specifies the depth of the new movie clip.

Returns

A reference to the newly created movie clip.

Description

Method; creates an empty movie clip as a child of an existing movie clip. This method behaves similarly to the attachMovie() method, but you don't need to provide an external linkage identifier for the new movie clip. The registration point for a newly created empty movie clip is the upper left corner. This method fails if any of the parameters are missing.

You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash.

Example

The following ActionScript creates a new movie clip at runtime and loads a JPEG image into the movie clip.

this.createEmptyMovieClip("logo_mc", this.getNextHighestDepth());
logo_mc.loadMovie("http://www.macromedia.com/images/shared/product_boxes/80x92/studio_flashpro.jpg");

See also

MovieClip.attachMovie()

Comments


recoveredfromflashMX2004 said on Aug 4, 2004 at 3:18 PM :
Uritsukidoji said on Jan 29, 2004 at 3:43 AM :

How to remove a movieclip created with createEmptyMovieClip() ?


richardlmk said on Jan 30, 2004 at 6:49 AM :

Example...

_root.createEmptyMovieClip("myClip_mc",1000);
_root.myClip_mc.lineStyle(2,0xCCCCCC,100); // Just to show...
_root.myClip_mc.lineTo(50,50); // ... the MC was created
_root.myClip_mc.removeMovieClip();

Nothing should appear on stage as MC is "immediately" removed.

If you have problems with movieClips at <strong>extreme</strong> depths, try using unloadMovie();

No screen name said on Mar 21, 2004 at 8:55 AM :

I have a problem with unloadmovie - I have a set of say 200 clips I wish to remove e.g. -
for (i=1; i<( clip_num+1 ); i++){
_root.instance3.thumbnail_mc[i].unloadMovie();
}
... and then want to recreate maybe 20 clips (with different content) the originals are still there.
I think this may be a timing problem - are there any event handlers I could use to detect when each clip has unloaded?
recoveredfromflashMX2004 said on Aug 4, 2004 at 3:20 PM :
No screen name said on Apr 21, 2004 at 7:50 PM :

How do I create a dotted line?


No screen name said on May 2, 2004 at 4:09 PM :

I am utterly stuck in removing empty movieclips...
What is the correct code for removing or unloading several empty MC
Is there 1 line that will do it all or do i have to unload each empty clip?


saester said on Jun 12, 2004 at 1:33 AM :

to remove empty clips created by duplicateMovieclip you should have used a naming convention as follows - "dupedClip"+i+"_mc" for each element in your loop - as such you can create a new function clearClips() that will simply run through the loop and call removeMovieClip() on each name - ie - you can do the following

for(i=0;i<numberOfClips-1;i++){
ptrClip = this["dupedClip"+i+"_mc"];
ptrClip.removeMovieClip();
}

this will remove all clips - ! ;)
romanticos said on Jul 5, 2004 at 2:17 AM :
Be careful not to try to set the _width or _height of an empty movie clip. Anything you try to put into that movie clip later will have visibility problems.
JohnGrden said on Jul 9, 2004 at 3:04 AM :
I can't seem to locate it, but removing a movie clip needs to be executed from the timeline that originally created the clip.

unloadMovie simply removes the contents of a clip, but the instance and the properties remain. To remove completely, use removeMovieClip()
Graham Butcher said on Nov 12, 2004 at 9:02 AM :
Taking the example above:
_root.createEmptyMovieClip("myClip_mc",1000);
_root.myClip_mc.lineStyle(2,0xCCCCCC,100); // Just to show...
_root.myClip_mc.lineTo(50,50); // ... the MC was created

This works, but when I add:
_root.myClip_mc._width = 100;

it no longer shows. Is this a bug or am I doing something wrong?

Using trace to show the width before and after the extra line, shows zero both times.
Fumio Nonaka said on Dec 5, 2004 at 2:04 AM :
The returned reference of the newly created MovieClip instance should
be supported for Flash Player 6 and later.
Francis Cheng said on Jan 17, 2005 at 10:31 PM :
Hi Graham,

What you have encountered is a timing issue. You have to make sure the clip you are loading is fully loaded before initializing or making any other changes to it. I assume you're also loading a movieclip (if you just copy and paste your code below, it works for me because there's nothing being loaded). I can reproduce your issue just by adding the line:

logo_mc._width

to the example in the Example section of MovieClip.createEmptyMovieClip.

To ensure it is fully loaded, you should use the MovieClipLoader class. In the code below, I use the onLoadInit event to wait for the right moment to assign a new width to the movie clip:

this.createEmptyMovieClip("logo_mc", this.getNextHighestDepth());
// create listener object to receive a message when the clip is completely loaded
var myListener:Object = new Object();
// onLoadInit is designed for initialization of the loaded movie clip
myListener.onLoadInit = function(targetMC:MovieClip) {
logo_mc._width = 200;
}
// We need to use the MovieClipLoader class
var imageLoader:MovieClipLoader = new MovieClipLoader();
// Add our listener object to the imageLoader's broadcast list
imageLoader.addListener(myListener);
// Note that we use MovieClipLoader.loadClip instead of loadMovie.
imageLoader.loadClip("http://www.macromedia.com/images/shared/product_boxes/80x92/studio_flashpro.jpg", logo_mc);
greg_brant said on Mar 22, 2005 at 5:41 AM :
I have this code which seems to follow Francis Chengs ideas about timing which i totally agree with, however.

the _width of the target_mc returns 0

so
(target_mc._parent._width/2);

returns the constant Infinity

i would have though that, onLoadInit, the movieClip would have inherited the dimensions of the jpeg that had been loaded??

imageLoader.prototype = new MovieClip();
Object.registerClass("imageHolder", imageLoader);
imageLoader.prototype.init = function() {
this.img = this.createEmptyMovieClip("theImg", this.getNextHighestDepth());
this.listener = new Object();
this.listener.onLoadComplete = this.executeOnLoad;
this.loader = new MovieClipLoader();
this.loader.addListener(this.listener);
this.loader.loadClip("myImage.jpg", this.theImg);
};
imageLoader.prototype.executeOnLoad = function(target_mc) {
target_mc._parent._x -= (target_mc._parent._width/2);
target_mc._parent._y -= (target_mc._parent._height/2);
};
madcat007 said on Jun 24, 2005 at 1:29 PM :
Hi I have created an emptymovieclip within a combo box on timeline 4 but when I try to refer to it in timeline 3 I can't seem to find it - can anyone help.

 

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/00001491.html