Removing Clip Instances and Main Movies
We’ve learned to create and refer to movie clips; now let’s see how to turn them into so many recycled electrons (in other words, blow ‘em away).
The manner in which we created an instance or a movie determines the
technique we use to remove that instance or movie later. We can
explicitly remove movies and instances using unloadMovie(
)
and removeMovieClip( )
.
Additionally, we may evict a clip implicitly by loading, attaching,
or duplicating a new clip in its stead. Let’s look at these
techniques individually.
Using unloadMovie( ) with Instances and Levels
The built-in unloadMovie(
)
function can remove any
clip instance or main movie—both those created manually and
those created via loadMovie( )
,
duplicateMovieClip( )
, and
attachMovie( )
.
It can be
invoked both as a global function and as a method:
unloadMovie(clipOrLevel
); // Global functionclipOrLevel
.unloadMovie( ); // Method
In global function form, clipOrLevel
is a
string indicating the path to the clip or level to unload. And due to
automatic value conversion, clipOrLevel
may also be a movie clip reference (movie clips are converted to
paths when used as strings). In method form,
clipOrLevel
must be a reference to a movie
clip object. The exact behavior of unloadMovie(
)
varies according to whether it is used on a level or an
instance.
Using unloadMovie( ) with levels
When applied to a level in the document stack (e.g.,
_level0
, _level1
,
_level2
), unloadMovie( )
completely removes the ...
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.