Run-time instances

Removal of Instance

Instance may be not only created but also removed.

For this purpose the action removeMovieClip() is used.

Let's modify our code one more time. Enter one line to the last line of the button event handler


removeMovieClip("ball" +(thenumber-4));

Imagine that you clicked your button first time – instance "ball1" will be created. The line of the code above will attempt to delete the instance "ball-3" that doesn't exist… this is some overhead here but it's not critical…

However starting from "ball5" the code will delete the instance which was created four steps behind. Every time you aggregate one more instance – one will be deleted. If you change parameter in the code to thenumber –1 it will keep only one instance on the stage.

It is a very good idea to remove clips from the stage if they are not necessary. In some case designers use loops to generate instances, which may cause your computer run out of memory if not destroyed.

Next