Printer Friendly Version

BellaOnline's Flash and Animation Editor

Setting Movie Clip Properties with ActionScript 3.0

One of the easiest ways to learn ActionScript in Flash CS3 is to first use the built-in features to perform a task and then write ActionScript code that will perform the same task. By comparing the two methods, you will gain a better understanding of how ActionScript works in Flash. In this tutorial, we will explore the properties for a Movie Clip object in the Properties Inspector and then write ActionScript code that will set values for these properties.

1. Start a new Flash document for ActionScript 3.0.

2. For the Oval tool, set the Fill to black and the Stroke to null. We are going to draw a snowflake.

3. While holding down the Shift key, click and drag to draw a circle at the top of the stage.

4. With the Selection tool, right-click on the circle. Choose Convert to Symbol from the menu. Name your symbol "mcSnowflake" and set the Type to Movie Clip.

You will notice that the mcSnowflake movie clip has been added to the Library Panel and the snowflake that we drew on the stage is now an instance of the mcSnowflake movie clip object. However, this instance still does not have a name. We need to give the snowflake on the stage a unique name for Flash and ActionScript to identify the instance.

5. In the Properties Inspector, change the placeholder Instance Name to "snowflake1_mc". While we are in the Properties Inspector, let's see what properties our snowflake has. As you can see, the snowflake that I drew has a Width and Height of 11 pixels. Because I drew the snowflake at the top of the stage, it has an X and Y position of 40 and 37.

6. Click Control, Test Movie to test our movie. The only thing that you should see is a small black circle at the top of the stage.

But snowflakes are not black. Now we will write some ActionScript to set the Alpha property value for our snowflake to a transparency of .2. In ActionScript 3.0, the Alpha value can be between 0 (100% transparent) and 1 (100% opaque). By setting the Alpha value to .2, our snowflake will be 20% transparent.

When coding in ActionScript, we will usually want to add our code to Frame 1 on a new actions layer in the Timeline. So, let's add a new layer to the Timeline.

7. Click on the Insert Layer button in the Timeline and rename our new layer "actions". The new actions layer will automatically be the top layer in the Timeline and we should be on Frame 1.

Now click Window, Actions to open the Actions panel. Because we are working on Frame 1 in the actions layer, the tab at the bottom of the panel should say actions:1. Click within the Script pane to begin the first line of code.

8. We need to tell Flash what instance of the snowflake we want to control with the code. Type "snowflake1_mc" on the first line. Next, add a period after the instance name to tell Flash that something more will follow.


9. We will tell Flash that we want to set a value for the Alpha property. Add "alpha" after the period.


10. Finally, we will set the Alpha value. Add a space after "alpha" and type "= .2;" to finish the code. This will set the Alpha to 20%.

snowflake1_mc.alpha = .2;

11. When we test our movie again, we should see a nice light gray snowflake.

Flash and Animation Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.

| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2018 Minerva WebWorks LLC. All rights reserved.

BellaOnline Editor