Lesson 10a - basic actions

explaining actions

Before you can add actions to Flash, you need to understand what an action is and how it works.

Actions are simply directions you can give to the Flash movie to tell it what to do. Actions are your way of controlling what happens and making the Flash movie interactive. For the purpose of your site, actions will be simple directions controlling the timeline.

Actions can be enacted two ways and will effect how they happen.

The first way actions can be enacted is in a frame. Actions can be placed within any keyframe (preferably an empty one). When your playhead reaches this frame in your movie, whatever actions you wrote in will take place.

The second way actions can be enacted is in through a button or movieclip event. Buttons and movieclips have "event handlers." These handlers a users interaction with your button or movieclip, and when that interaction happens, the actions take place. For a button, this can be when the user presses, rolls over, or rolls off the button, for example. For a movieclip, it can be when the movieclip finishes loading, or repeats a frame. Essentially, the handlers trigger the event that causes the action.

Give actions a home

So now you know how actions work. But where do you write in actions? This part is twofold. As you've just read, actions can be put into keyframes or they can be applied to buttons and movieclips. Let's start with putting actions in keyframes.

First we need to make a layer that is dedicated to actions. Since actions take place when the playhead reaches the frame, it doesn't matter what layer actions are on. This being the case, it is always a good idea to make a layer just for actions.

When you know what frame you want to trigger your actions, simply insert a blank keyframe in that frame. We will put our actions in this frame (it should be noted that you can add actions to as many frames as you want in your actions layer). Next, click on your empty key frame.

Now we need to bring up a new panel, the "Actions" panel. To do this, go to the top menu and click Window > Actions (F9). This will bring up the actions panel. You will notice a blank area to type in as the prominent area of your Actions Panel. This is where you will write in your actions.

Adding actions to a button is very similar. Simply bring up your Actions panel as described above and click on your button once. You will notice that it now says Actions - Button on the top tab. As with frames, write your actions in here. This is covered more extensively in the next lesson.

controlling the timeline

Most of the basic actions you will learn control the timeline. The basic syntax is the same for all actions. Here is a short list of actions that control the timeline:

stop();

This stops the timeline.

play();

The makes the timeline play.

gotoAndStop(number or "frame label");

This makes the time jump to the number or frame label (in quotes) you specify in the parenthesis and stop.

gotoAndPlay(number or "frame label");

This makes the time jump to the number or frame label (in quotes) you specify in the parenthesis and play.

Changing properties

Through actions you can also change a movieclips properties. It is written like this:

instancename._property = newvalue;

In this example, instancename is the instance name of the movieclip you want to affect. Property is the name of the property you want to change (and this is always preceded by an underscore), and new value is the value you want to change the property to. The value depends on what property you are changing, but all values are numbers. Some values are percentages, like alpha. Some values are pixel values, like width and height. Some value are coordinates, like x and y. The kind of value depends on the property you are changing.

Here is another example. If i want to change my movieclip mc1 to have 50% transperancy (alpha), I would write it as such:

mc1._alpha = 50;

Actions become much more powerful when we apply them to buttons, so read on to find out how!

Back to Lesson 10 . On to Lesson 11