PDA

View Full Version : Removing a movieclip completely



four4swords
November 13th, 2009, 11:42 PM
Hi,

How do I completely remove a movieclip? I am able to create a moviecilp, then add it to the stage with addChild(), then I am able to remove it from the display list by using removeChild()

However, the movieclip is still present. Here's what I did.

I created a movieclip.. which has a trace on the 10th frame : trace("Movieclip still exists")

On the 20th frame I have : a reference to a function which is on the document class
This function is this


function removeMC():void{
removeChild(mc)
mc = null;
}After setting up all the linkages I create and add the movieclip onto the stage


var mc:ballmovieclip = new ballmovieclip()
addChild(mc)What should happen.. is that the movieclip will be created and added to the stage.. It will play through it's frames til it hits 10 , at which then it outputs the trace message, continuing on.. til frame 20, it calls the function to remove the movieclip from the displaylist which it does.. However, the movieclip keeps playing and keeps on sending out the trace messages.

I thought since the movieclip was removed from the stage.. it would not continue to play through it's frames.. but it does..

How do I get rid of the movieclip completely so this doesn't happen?

Thanks.

Shaedo
November 14th, 2009, 02:32 AM
http://www.kirupa.com/forum/showthread.php?t=338766

four4swords
November 14th, 2009, 04:36 AM
I'm sorry.. but what did you want me to take away from that thread?

I tried setting my movieclip to "null".. but still it does not work.

I've attached a fla so you can better understand my problem.

Inside, a movieclip is attached onto the stage... and at the end of the frames.. it calls a function to fully remove it from the stage and not play any more traces..

But i can't seem to get it to work..

Any ideas?

kadaj
November 14th, 2009, 04:55 AM
I'm sorry.. but what did you want me to take away from that thread?

I tried setting my movieclip to "null".. but still it does not work.

I've attached a fla so you can better understand my problem.

Inside, a movieclip is attached onto the stage... and at the end of the frames.. it calls a function to fully remove it from the stage and not play any more traces..

But i can't seem to get it to work..

Any ideas?

In you removeMC.fla inside the Symbol1 movieclip on frame 40 add a stop(); so that it stops looping and doesn't produce an error.

After that code it will look like


trace("Now removing movieclip --- There should be no more traces after this as this moviecip does not exist anymore");
MovieClip(root).removeMyclip()
stop();

four4swords
November 14th, 2009, 05:07 AM
Yes that does stop the error from happening. But that just stops the error, I want the clip to be actually removed and therefore not have to face that error at all.

There could be a situation.. where a movieclip is playing, and at an unknown time, the remove function could be called to remove the movieclip from the stage.. and prevent it from doing any more traces. In those instances, it would be better to just have the movieclip disappear from existence.. than to put a stop.

Good idea though, just not quite what I'm after..
Any other ideas?

four4swords
November 15th, 2009, 04:29 PM
*bump*

Scythe
November 15th, 2009, 04:50 PM
You cannot force garbage collection. Believe me, people have tried.

This stops the error by checking to see if the root property is null or not:

if (root) {
MovieClip(root).removeMyclip();
}
Or course the clip will keep playing and tracing unless you stop it, which there is absolutely no reason not to since why would you want a clip to play if it's not even supposed to exist?

There should be no more traces after this as this moviecip does not exist anymore

That's not true, by the way. An object having no references doesn't mean it doesn't exist. Only garbage collection can remove it entirely.

four4swords
November 15th, 2009, 04:55 PM
Oh ok.. So I've done everything I can up til this one to remove it.. and only the garbage collector can finally do the last removal.

Thanks for the heads up.