Main Content
Removing Movie Clips
Welcome to Foundation Flash tutorials. In this tutorial you will learn about the removeMovieClip function. If you remember, in our last tutorial, I told you how to create a custom function to duplicate a movie clip. In this tutorial, I will teach you how to make a reset button to clear all the balls, using the removeMovieClip function. It will look a little like this:
So, create a button, with RESET written on it. Then, in its ActionScript box, type:
on(press){ _root.remove = true; } on(release){ _root.remove = false; } on(releaseOutside){ _root.remove = false; }
So, when it is pressed, a variable called remove (which we havent created yet) will equal true, and then when it is released, or released outside of the button, it will equal false. Now, in the first frame of your movie, just simply type, above everything else:
var remove = false;
Now we have created our remove variable.The last thing to do is to remove our ball when this variable is true. So, go into our ball Movie Clip, and in the on enter frame event, type:
if(_root.remove == true){ this.removeMovieClip(); this._x = random(550); this._y = random(350); }
This will move our main ball on the stage to a new position, and remove all of our duplicated balls when remove equals true. The reason that the original isn't removed is that Flash still needs it to duplicate more Movie Clips from it later on.This is quite an important point: even if we didn't want to duplicate from it, we may still have to keep it. If in doubt, move it off-stage and make it invisible.
Well, that's it, thank you for reading, and I hope you'll join us next time,
Leon.