View comments | RSS feed

MovieClip.removeMovieClip()

Availability

Flash Player 5.

Usage

my_mc.removeMovieClip() : Void

Parameters

None.

Returns

Nothing.

Description

Method; removes a movie clip instance created with duplicateMovieClip(), MovieClip.duplicateMovieClip(), or MovieClip.attachMovie().

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

Each time you click a button in the following example, you attach a movie clip instance to the Stage in a random position. When you click a movie clip instance, you remove that instance from the SWF file.

function randRange(min:Number, max:Number):Number {
   var randNum:Number = Math.round(Math.random()*(max-min))+min;
   return randNum;
}
var bugNum:Number = 0;
addBug_btn.onRelease = addBug;
function addBug() {
   var thisBug:MovieClip = this._parent.attachMovie("bug_id", "bug"+bugNum+"_mc", bugNum, {_x:randRange(50, 500), _y:randRange(50, 350)});
   thisBug.onRelease = function() {
      this.removeMovieClip();
   };
   bugNum++;
}

Comments


dougconing said on Sep 20, 2004 at 10:38 AM :
If you use "this.getNextHighestDepth()" and V2 components in a movie, then removeMovieClip() will NOT work.

See this fix:

http://www.macromedia.com/support/flash/ts/documents/remove_mc_depth.htm?pss=rss_flash_19435
hypoStiller said on Nov 9, 2004 at 1:21 PM :
This method also works with movie clips created by the MovieClip.createEmptyMovieClip() method.
murk379 said on Nov 25, 2004 at 8:13 PM :
dougconing: thankyou thankyou thankyou for posting your warning about getNextHighestDepth with V2 Components!

I think Macromedia ought to make that particular issue a *little* more obvious!
Sardok said on Mar 9, 2005 at 7:16 AM :
Note that any movieclip with a depth of less than zero cannot be removed using this function. Even without using V2 components.

To be certain, first swap the depth of the movieclip to any positive number before trying to remove any movieclip using [b]my_mc.removeMovieClip()[b].
areohbee said on Apr 6, 2005 at 8:47 PM :
removeMovieClip will not work if the symbol type is "Button". A work-around is to make it a "MovieClip" and then assign it the class "mx.controls.SimpleButton".
sethrd11 said on May 16, 2005 at 9:49 PM :
i actually had to do a search to find out that removeMovieClip doesnt work with getNextHighestDepth and V2 components...
Francis Cheng said on May 16, 2005 at 11:07 PM :
Thanks to everyone for adding such helpful information. I've updated the source file with this information.
No screen name said on Jun 6, 2005 at 9:06 AM :
I'm no genius, but isn't the bracket and comma out of order?

my_mc.attachMovie(idName:String, newName:String, depth:Number [, initObject:Object]) : MovieClip

The error is between depth and the initObject.
Helper Bee said on Jun 6, 2005 at 10:21 AM :
No, the brackets indcate that anything inside them is optional. So if you want to use the initObject parameter, the you would use the comma. That's why they are both inside the [brackets]. You never type the [ ]. They are just a syntax convention to indicate that something is optional.
myIP said on Aug 23, 2005 at 9:38 AM :
Thanks dougconing and sethrd11 for posting about the getNextHighestDepth issue!!!
adam1026dotcom said on Sep 8, 2005 at 1:40 PM :
You guys saved my freakin' life! I had no idea the v2 components would conflict with getNextHighestDepth(). I spend way too many hours trying to figure out why is was not working before I turned here.

Thanks!
adv39621 said on Sep 13, 2005 at 1:53 PM :
removeMovieClip does not work with any depth parameter, not only with NextHighestDepth, according to my experience.
FishmongerX said on Sep 26, 2005 at 2:35 PM :
Thank you dougconing for heads up on that bug.

Its unfortunate that we have to spend hours debugging our code in frustration to find out 6-10+ hours later that its not user error, but infact another macromedia bug. Atleast this one isn't as bad as the buggy V2 comboBox that takes over the focusmanager.

I'd like to request bugs like this be posted in a new section in Help and Livedocs called "Bugs". That way we can find them were we are looking.

Pardon my frustration.
justforclubs said on Sep 30, 2005 at 10:35 AM :
When I do a for(in) loop to look at objects in _root I find that sometimes removeMovieClip does not actually delete a movieClip even though it disappers from view. Does anyone know a fail-safe way to delete a movieClip from _root?

 

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