
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
336
|
Chapter 13: Movie Clips
command first tries to convert it to a string, but because newClip1 looks to the inter-
preter like an
undefined variable, the conversion yields the empty string. Luckily, you
can again use the return value stored in
newClip_mc to refer to the newly created clip:
newClip_mc = _root.attachMovie("Symbol 1", newClip1, 0);
trace(newClip_mc); // Displays _level0.
// (the clip's name is an empty string!)
What if newName is specified as a legal identifier, such as ball_mc, that already refers to
an existing movie clip? Again, the attachMovie() command first tries to convert it to a
string, which (referring to Table 3-2 for string conversion of movie clips) yields the
interim string “_level0.ball_mc” for
newName. This series of conversions results in the
newly created movie clip having the incorrect name “_level0._level0.ball_mc”. Luck-
ily, yet again you can use the return value stored in
newClip_mc to refer to the newly
created clip properly:
//Assume ball_mc is an existing (valid) movie clip identifier
newClip_mc = _root.attachMovie("Symbol 1", ball_mc, 0);
trace(newClip_mc); // Displays "_level0._level0.ball_mc"
As you can see, life is much easier when we make sure to provide a string that con-
verts to a legal identifier for
newName.
Creating instances with createEmptyMovieClip( ...