Managing Movie Clip Instances - Page 1 by kirupa | 7
September 2008
For many types of projects, you will be instantiating movie clips from your
library and displaying them on your stage. Instantiating is a fancy word word
for creating a copy of or duplicating. An
earlier tutorial covers just how you would do that. One thing that the
earlier tutorial does not cover is how to actually manage those instantiated movie
clips. Once a movie clip has found its way into your stage, how can you work
with it later? That is where this tutorial comes in.
Click on the following blob of circles to see an example
where, each time you click, the circles that make up the blob
disappear and are replaced with new circles:
This is done by me storing a reference to each movie clip
and deleting them later. In this tutorial, let's learn how
to do that.
Let's Get Started What
you are going to do is create a circle movie clip whose
class name is BlueCircle. If you need further instructions
on how to do that, the following instructions will help you
out. Otherwise, skip over to the
next page
where we introduce the code and explain what is going on:
First, create a new animation in Flash CS3. From the
Properties panel, click the button next to the Size text
and set the animation's width and height to 300 pixels
by 200 pixels respectively:
[ set your
animation's width/height to 300 by 200 ]
Now that our stage's width and height have
been setup just the way we want, let's draw a circle.
Using the Circle tool, draw a circle with a blue
solid-fill color:
[ draw a blue, solid,
filled circle ]
Make sure your circle has been selected
and press F8 or go to Modify | Convert to Symbol. The
Convert to Symbol window will appear. For name, enter
circle and make sure the Movie Clip
option has been selected:
[ give your symbol the name circle and
make sure it is also set to be a movie clip ]
Do not hit OK just yet. Let's make some
more modifications.
From the same Convert to Symbol window,
find the area marked Linkage. If you do not see the
Linkage area, press the Advanced button to display it.
Check the box that says Export for ActionScript.
A few lines above that, in the Class field, replace
whatever text is displayed (probably circle) with the
text BlueCircle:
[ check 'Export for ActionScript and
enter BlueCircle for your class ]
The Base class field will automatically be
populated for you, but if it hasn't, make sure to enter
flash.display.MovieClip as
shown in the above image.
Press OK to close the Convert to Symbol
window. After you have pressed OK, you will see your
Library display your newly created symbol:
[ your circle in your Library ]
If you do not
see your Library, press Ctrl + L to display it.
At this point, your circle movie clip is
stored in the Library, and you have a copy of that same
clip on your stage right now. Select the blue circle
movie clip located on your stage and delete it by
pressing the Delete key. You should now have a blank
stage with nothing in it.
Ok, now we are in a good spot, for you have your library
setup. In the
next page, let's add the code and explain what was done
to keep track of the newly added movie clips.