
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
362
|
Chapter 13: Movie Clips
unloadMovie(x); // If x doesn't exist, x yields undefined, so
// the function operates on the current timeline
unloadMovie(""); // The target is the empty string, so the function operates
// on the current timeline
This can cause some quite unexpected results. Consider what happens if we refer to
a level that doesn’t exist:
unloadMovie(_level1);
If _level1 is empty, the interpreter resolves the reference as though it were an unde-
clared variable. This yields undefined, so the function operates on the current time-
line, not
_level1! So, how do we accommodate this behavior? There are a few
options. We can check for the existence of our target before executing a function on
it:
if (_level1) {
unloadMovie(_level1);
}
Or, we can choose to always use a string to indicate the path to our target. If the path
specified in our string does not resolve to a real clip, the function fails silently:
unloadMovie("_level1");
In some cases, we can use the equivalent numeric function for our operation:
unloadMovieNum(1);
Finally, we can choose to avoid the issue altogether by always using clip methods:
_level1.unloadMovie();
For reference, here are the troublemakers (the ActionScript global functions that take
target parameters):
duplicateMovieClip()
loadMovie()
loadVariables()
print( ...