What is the difference?
In practice, they do the same, but are used differently. removeMovieClip can be used as a global method or local method (removeMovieClip ( someMC ) or someMC.removeMovieClip() ). destroyObject can only be used inside of a class that inherits from UIObject somewhere on the inheritance chain and takes the string name of the movie clip, not a movie clip path (destroyObject ( “someMC” ) ).
Fundamentally, however, they are very different. removeMovieClip can only remove movie clips that are in positive depths, 0 included. Therefore, if you dragged a List component on the stage, removeMovieClip will not work on it unless you use the swapDepths command to bring the component to a positive depth (hopefully unoccupied) and then remove it. If the playhead leaves, however, the frame where the List component is, and then returns, the List too will re-appear.
destroyObject does this for you automatically. Additionally, since movie clips/components in classes use member variables, it takes the liberty in deleting the component’s name; not the variable itself mind you, but the name nonetheless.
Neither deal with pointers to the object you may have created elsewhere.
hey, what happened to all the comments for this post? there was some really good info in them…
Oh no… not again… I hate MT…
I’ll see if I can fix it this weekend.
actually, i had the wrong post..i was talking about all the comments in you web apps/window clients post.
i didn’t even think removeMovieClip would work on a clip placed by hand on the timeline. it’s only suppose to work on clips placed with duplicateMovieClip or attachMovie.
if destroyOjbect has to have the uiobject code to work, then i could see it not being very useful in projects that don’t use the uiobjects code.
also, could you use delete instead?
removeMovieClip won’t work because it only works on clips in positive depths. Symbols dropped on the stage are automatically put in negative depths when compiled, thus, removeMovieClip won’t work on them… unless you first swap them to a postiive depth, then call it.
destroyObject does this for you, and safely.
If you don’t use the framework, then correct, it won’t work at all.
delete only delete’s a variable from memory (supposedly), and returns true or false. However, since movie clips are physical objects, delete could delete the reference, but not the actual movie clip, so no delete won’t work.
actually, how about just use unloadMovie? like
someMC.unloadMovie()
unloadMovie will trigger an onUnload, and even remove all of the movie clip’s contents… but the movie clip shell is still there. removeMovieClip kills the container shell as well, obliterating the movie clip entirely… but who knows if it gets waxed from RAM…
createEmptyMovieClip(“test_mc”, 0);
test_mc.onUnload = function(o)
{
trace(“onUnload”);
};
test_mc.onEnterFrame = function()
{
trace(“frame later, I’m still alive: ” + this);
};
test_mc.unloadMovie();
trace(“still there?: ” + test_mc);