Creating movie clips at runtime Not only can (Web hosting account)
Creating movie clips at runtime Not only can you create movie clip instances in the Flash authoring environment, but you can also create them at runtime. ActionScript provides three ways to create new movie clips at runtime: By creating a new, empty movie clip instance By duplicating an existing movie clip instance By attaching an instance of a movie clip library symbol to the Stage Each movie clip instance you create at runtime must have an instance name and a depth (stacking, or z-order) value. The depth you specify determines how the new clip overlaps with other clips on the same Timeline. (See Managing movie clip depths on page 129.) Creating an empty movie clip To create an empty movie clip on the Stage, use the createEmptyMovieClip() method of the MovieClip class. This method creates a movie clip as a child of the clip that calls the method. The registration point for a newly created empty movie clip is the upper left corner. For example, the following code creates a new child movie clip named new_mc at a depth of 10 in the movie clip named parent_mc. parent_mc.createEmptyMovieClip(”new_mc”, 10); The following code creates a new movie clip named canvas_mc on the root Timeline of the SWF file in which the script is run, and then invokes loadMovie() to load an external JPEG file into itself. _root.createEmptyMovieClip(”canvas_mc”, 10); canvas_mc.loadMovie(”flowers.jpg”); For more information, see MovieClip.createEmptyMovieClip() on page 494. Duplicating or removing a movie clip To duplicate or remove movie clip instances, use the duplicateMovieClip() or removeMovieClip() global functions, or the MovieClip class methods of the same name. The duplicateMovieClip() method creates a new instance of an existing movie clip instance, assigns it a new instance name, and gives it a depth, or z-order. A duplicated movie clip always starts at Frame 1 even if the original movie clip was on another frame when duplicated, and is always in front of all previously defined movie clips placed on the Timeline. To delete a movie clip you created with duplicateMovieClip(), use removeMovieClip(). Duplicated movie clips are also removed if the parent movie clip is deleted. For more information, see duplicateMovieClip() on page 373 and removeMovieClip() on page 605. 126 Chapter 7: Working with Movie Clips
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.