Adding Empty Movie Clips


Aside from adding movie clip instances of exported movie clip symbols, you can also programmatically add movie clip instances that have no symbol. The createEmptyMovieClip() method, as the name implies, adds a new empty movie clip instance. The benefit of an empty movie clip instance might not be immediately apparent. However, there are many cases in which it can be useful. Remember that movie clips can contain nested movie clips. If you move the parent movie clip, for example, the nested movie clips are also moved. So if you attach movie clips within an empty movie clip, the parent movie clip is a convenient way to group nested instances. Additionally, as you'll read in the next section, you can draw programmatically within a movie clip. That means that you can add a new empty movie clip and then you can draw content within that instance.

Regardless of how you intend to work with the new empty movie clip instance, you can create it the same way. The createEmptyMovieClip() method is a method of the MovieClip class, and it adds a new empty movie clip instance nested within the object from which it is called. The method requires two parameters: the new instance name and the depth at which to add the instance. The following code adds a new movie clip instance called exampleClip:

   this.createEmptyMovieClip("exampleClip", this.getNextHighestDepth());


As with the attachMovie() method, the createEmptyMovieClip() method returns a reference to the new movie clip.




Macromedia Flash 8 ActionScript Training from the Source
Macromedia Flash 8 ActionScript: Training from the Source
ISBN: 0321336194
EAN: 2147483647
Year: 2007
Pages: 221

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net