This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org. This exercise will cover
This exercise will cover
The creation of graphics, buttons and movie clips.
Simple shape tweening.
The use of frame labels.
Creating instances of movie clips and buttons.
Controlling different timelines.
How you can use movie clips to control an animated sequence.
How to enable and disable buttons

Using the circle shape tool draw an egg shape on the main timeline. Select the egg and hit F8 to convert it to a movie clip. Check to see that you have Movie Clip selected and name your movie clip egg_mc and hit ok.
Name the layer that your egg is on to egg_mc. We want to refer to this movie clip when we add some actionscript to our file so we much give it an instance name. It is very important to name your movie clips to match your actionscript. Be sure to recognise if you have used uppercase or lowercase letters and avoid using numbers at the beginning of an instance name. For now we will give our egg_mc the instance name of egg_mc. Select egg_mc and in the property inspector where you see <instance> type egg_mc.





[as]stop();
[/as]
[as]//this stops the line1_mc's timeline
stop();
//this starts line2_mc playing from the label marker "mend" on the main timeline
_root.line2_mc.play();
[/as]
[as]stop();
[/as]
on frame 11
[as]//this stops the line2_mc's timeline
stop();
//this starts line3_mc playing on the main timeline
_root.line3_mc.play()
[/as]
[as]// this starts line1_mc playing from the label marker "mend" on the main timeline
_root.line1_mc.gotoAndPlay("mend");
[/as]
[as]stop();
[/as]
[as]//this stops the line3_mc's timeline
stop();
//this starts line4_mc playing on the main timeline
_root.line4_mc.play();
[/as]
[as]//this starts line2_mc playing from the label marker "mend" on the main timeline
_root.line2_mc.gotoAndPlay("mend");
[/as]
[as]stop();
[/as]
[as]stop();
[/as]
[as]//this starts line3_mc playing from the label marker "mend" on the main timeline
_root.line3_mc.gotoAndPlay("mend");
[/as]




[as]//this stops our movie from showing at fullscreen
fscommand("fullscreen", "false");
//this stops our movie from scaling
fscommand("allowscale", "false");
//this stops the main timeline of the movie
stop();
//when we click on the egg crack button
crack_btn.onRelease=function(){
//this starts line1_mc playing from the next frame in the movie clip
line1_mc.gotoAndPlay(line1_mc._currentframe+1);
//or you could just use line1_mc.play();
}
//when we click on the egg mend button
mend_btn.onRelease=function(){
//this starts line4_mc playing from the label marker "mend"
line4_mc.play("mend");
}
[/as]
The comments should be pretty self-explanatory. To test your movie, go to Control/Test Movie at the menu above.
To gain a better understanding of the sequence of events you are triggering see what happens when you click the mend egg button first. This is just a way to get a better understanding of how you can use movie clips to control an animated sequence.
This is all well and good as an example but it is not finished yet. We really need to make sure that no one else presses the wrong button and the wrong time. The easiest way to continue with out movie clip control functions is to make a few movie clips enable and disable our buttons.
Time to add some more actions.
On frame 1 of the Main timeline on the actions layer
[as]//this disables out egg mend button to begin with
mend_btn.enabled=false;
[/as]
[as]stop();
//this enables the egg crack button on the main timeline
_root.crack_btn.enabled=true;
[/as]
[as]//this disables out egg mend button on the main timeline
mend_btn.enabled=false;
[/as]
[as]stop();
//this enables our egg mend button on the main timeline
_root.mend_btn.enabled=true;
[/as]
[as]//this disables our egg mend button on the main timeline
_root.mend_btn.enabled=false;
[/as]

Select egg_mc and double click or right click to edit in place. Rename the layer with the egg shape on it to eggopen_mc. Select the shape including the outline and hit F8 to convert it to a movie clip. Call it eggopen_mc and be sure that movie clip is selected and hit ok.






![]()



Select frame 2 in the time line and select Shape Tween in the Property Inspector.
To create a mask double click on the mask layer, almost on top of the layer icon to open the layer properties window. Next to type click mask and click ok.

Now that our egg is cracking and opening we need some little ducklings to hatch when our egg opens. Take another look at the library in the graphics.fla and you will see an orange_duck_mc, drag this movie clip into the MovieClips_02.fla
We will use this movie clip for something else later but for now we need lost of excited ducklings to jump about. Select orange_duck_mc in the library window and right click and select duplicate to do just that. Call it ducklingsduplicate_mc or something shorter if you like.

Double click on ducklingsduplicate_mc in the library to edit it and delete the top layer that says actons.
Return to the egg_mcon scene one and double click or right click to edit in place. Add a new layer and call it ducklings. On this layer place a few instances of the ducklingsduplicate_mc by dragging them out of the library. When you have a few lined up, select all of them and hit F8 to convert them to a movie clip. Call it ducklings_mc and hit ok.




You may want to make this duck a little larger with the scale tool. If you hold down the shift key while you scale an object is will scale in proportion, otherwise your duck may become tall and thin or short and fat.
So now that all our graphics are finished it is time to make some buttons. Back on the main timeline on the buttons layer use the text tool to type "duck flap", "egg open" and "reset egg". Select "duck flap" and hit F8 to convert it to a button. Make sure you have button selected and call it flap_btn and hit okay. Select "egg open" and hit F8 to convert it to a button. Call it open_btn and hit okay. Then select "reset egg" and hit F8 to convert it to a button. Call it reset_btn and hit okay.
Double click on flap_btn to edit the button in place. Hit F6to create keyframes for the over, down and hit states. Make sure you draw a square shape on the hit state frame to cover the height and width of the text. Simple text isn't always recognised as a true hit area in flash so it is always a good idea to add a shape to the hit area when using text buttons. Remember to do the same to the open_btn and reset_btn


[as]stop();
[/as]
[as]//this disables the egg open button on the main timeline
_root.open_btn.enabled=false;
[/as]
[as]//go back to frame one of the egg_mc timeline
gotoAndStop(1);
//this will play the open egg movie clip
//we use _parent because we are referring to a nested movie clip (eggopen_mc) that exists within the egg_mc
_parent.eggopen_mc.gotoAndPlay(2);
[/as]
[as]stop();
[/as]
[as]//this stops the eggopen_mc's timeline
stop();
//this will play the ducklings movie clip
//we use _parent because we are referring to a nested movie clip (ducklings_mc) that exists within the egg_mc
_parent.ducklings_mc.play();
[/as]
[as]stop();
[/as]
[as]//this stops ducklings_mc timeline
stop();
//this playes the duck_mc on the main timeline
// we use _root because it refers to duck_mc that exists on the maintimeline _root.duck_mc.play();
[/as]
On the first frame of the actions layer in scene one add these actions below those already existing.
[as]//two different ways to create the same effect
//option one, when we click on the duck flap button
flap_btn.onRelease=function(){
//this tells the duck_mc to play duck_mc.play();
}
//option two, when we click on the duck movie clip
duck_mc.onRelease=function(){
//we can use this.play() because it is referring to itself this.play();
}
//when we click on the egg open button
open_btn.onRelease=function(){
//this starts the crack_mc which is nested inside egg_mc to play
egg_mc.crack_mc.play();
//disable the egg crack button
crack_btn.enabled=false;
}
//when we click on the reset egg button
reset_btn.onRelease=function(){
//this returns the following movie clips to the first frames of their timelines
egg_mc.eggopen_mc.gotoAndStop(1);
egg_mc.ducklings_mc.gotoAndStop(1);
line1_mc.gotoAndStop(1);
line2_mc.gotoAndStop(1);
line3_mc.gotoAndStop(1);
line4_mc.gotoAndStop(1);
//enable the egg open button
open_btn.enabled=true;
//enable the egg crack button
crack_btn.enabled=true;
}
[/as]
[as]//this disables the egg crack button on the main timeline
_root.crack_btn.enabled=false;
//this disables the egg open button on the main timeline
_root.open_btn.enabled=false;
//when we click on the reset egg button
reset_btn.onRelease=function(){
//this returns the following movie clips to the first frames of their timelines
egg_mc.eggopen_mc.gotoAndStop(1);
egg_mc.ducklings_mc.gotoAndStop(1);
line1_mc.gotoAndStop(1);
line2_mc.gotoAndStop(1);
line3_mc.gotoAndStop(1);
line4_mc.gotoAndStop(1);
//enable the egg open button
open_btn.enabled=true;
//enable the egg crack button
crack_btn.enabled=true;
}
[/as]
[as]//this enable our egg open button on the main timeline
_root.open_btn.enabled=true;
[/as]