Macromedia Flash8 Bible

Now that you have a general picture of what actions do, let's look at five common actions in detail. At this point, we're describing only the functionality of each action, not how to add an action to your movie. We provide information on adding an action in the next section, "Making Actions Happen with Event Handlers."

Cross-Reference 

You will find coverage of further actions (and full-blown ActionScript) in later chapters.

Actions in the Flash interface appear alphabetically sorted from top to bottom. In the following sections, complementary actions are grouped together.

gotoAndPlay and gotoAndStop

These "go to" actions change the current frame of the movie to the target frame specified as the action's parameter. There are two variations:

Both actions enable you to jump to certain areas of the Flash movie. The parameters of these actions start with the largest time unit, the scene, and end with the smallest one, the frame.

You can specify frames in other scenes as the target of goto actions with the scene parameter. As shown in the following code, you type the name of the scene first, with double quotes around the name, and then the frame number (without quotes) or frame label. In this example, "Scene 2" is the name of the scene and "animate_in" is the frame label in that scene to jump to.

gotoAndPlay("Scene 2", "animate_in");

However, if you only specify one parameter in a gotoAndPlay or gotoAndStop action, the parameter is interpreted as a frame label. For example, the following code tells the current timeline to jump to its "menu" frame label:

gotoAndStop("menu");

Caution 

While we haven't looked at actions specifically for use in Movie Clip instances, make a note that you can't use a goto action specifying a scene within a Movie Clip instance. In this case, you should target the Main Timeline to go to and stop (or play) the keyframe label in the desired scene, omitting the Scene's name. For example, _root.gotoAndStop("products"); executed from a Movie Clip Timeline would tell the Main Timeline to go to and stop on the frame label products, which would be located in a different scene.

There are three methods of specifying the frame to which the movie should go when it receives a goto action. The methods for specifying the frame are

Cross-Reference 

Expressions are covered in Chapter 24, "Knowing the Nuts and Bolts of Code."

nextFrame and prevFrame

The nextFrame and prevFrame actions act like a gotoAndStop action, in that they both transport the timeline to a new position and stop.

nextScene and prevScene

These actions advance the Flash movie to a new scene. Here's how they work:

Note 

The nextScene and prevScene actions do not automatically recycle the scenes when the last or first scene is reached, respectively. For example, if you have three scenes and use a nextScene action while the movie is on the last scene, the movie will not jump back to the first scene.

Tip 

While you may find it simpler to segment your Flash content across several scenes as you begin to learn Flash, most seasoned Flash designers and developers only use one scene, and separate content across several Movie Clip symbols placed on one or more frames of Scene 1. Scenes are not compatible with standard targeting syntax, as you'll learn in the next chapter.

On the CD-ROM 

You can find an example of nextScene and prevScene usage in the document named nextScene.fla in the ch18 folder of this book's CD-ROM.

Play and Stop

These simple actions are the true foundations of Flash timeline control. play sets a movie or a Movie Clip instance in motion. When a play action is executed, Flash starts the sequential display of each frame's contents along the current timeline.

The rate at which the frames are displayed is measured as frames per second, or fps. The fps rate can be set from 0.01 to 120 (meaning that the play action can cause the display of as little as 1 frame every 100 seconds to as many as 120 frames in 1 second, subject to the limitations of the computer's processing speed). The default fps is 12.

Once play has started, frames continue to be displayed one after the other, until another action interrupts the flow, or the end of the movie or Movie Clip's timeline is reached. If the end of a movie's timeline is reached, the movie either loops (begins playing again at frame 1, Scene 1), or stops on the last frame.

Once the end of the Movie Clip's timeline is reached, playback loops back to the beginning of the clip, and the clip continues playing. To prevent looping, add a stop action to the last frame of your Movie Clip.

Note 

A single play action affects only a single timeline, whether that timeline is the main movie timeline or the timeline of a Movie Clip instance. For example, a play action executed inside a Movie Clip does not cause the Main Timeline to begin playing. Likewise, any goto action on the Main Timeline doesn't migrate to the Movie Clips that reside there. A timeline must be specifically targeted to control playback along that timeline. If there is no specified target, the action is referring to its own timeline. However, this is not the case for animations within Graphic symbol instances. An animation in a Graphic symbol is controlled by actions on the timeline in which the symbol instance is present — Flash ignores actions on a Graphic symbol's timeline.

stop, as you may have guessed, halts the progression of a movie or Movie Clip that is in a play state. stop is often used with buttons for user-controlled playback of a movie, or on frames to end an animated sequence.

Tip 

Movie Clip instances placed on any timeline begin to play automatically. Remember to add a stop action on the first frame of a Movie Clip if you don't want it to play right away.

stopAllSounds

A simple but powerful action that mutes any sounds playing in the movie at the time the action is executed, stopAllSounds does not disable sounds permanently — it simply cancels any sounds that happen to be currently playing. It is sometimes used as a quick-and-dirty method for making buttons that shut off background looping soundtracks. stopAllSounds is not appropriate for controlling whether individual (or specific) sounds are played or muted.

getURL

Want to link to a Web page from a Flash movie? No problem. That's what getURL is for. You can find the getURL action in the Global Functions ð Browser/Network booklet of the Actions panel. getURL is simply Flash's method of making a conventional hypertext link. It's nearly the equivalent of an anchor tag in HTML (<a href="...">), except that Flash's getURL can also send variables for form submission. getURL can be used to link to a standard Web page, an FTP site, another Flash movie, an executable, a server-side script, or anything that exists on the Internet or on an accessible local file system.

getURL has three parameters that are familiar to Web builders (the first one, url, is required for this action to work):

Tip 

getURL functions in the Test Movie environment. Both the Flash stand-alone player and the Test Movie command give you access to external and/or local URLs.

Let's look at some quick examples of how you can write a getURL action. The following code tells the browser to load the URL, www.wiley.com, into the current browser window:

getURL("http://www.wiley.com");

Alternatively, you can specify a unique target for the loaded URL. The following example loads an HTML document named menu.html into a frame named menu_frame:

getURL("menu.html", "menu_frame");

A more advanced usage of the getURL action sends variables from the Flash movie to a Web server's script, which is set up to receive the variables. The following code looks up the version of the Flash Player playing the movie and sends to a script that logs the information:

var playerVersion = getVersion(); getURL("http://www.mysite.com/scripts/log.cfm","_self","GET");

As we mentioned with the goto actions, you can also use expressions with getURL actions. Expressions can be used as parameters of any ActionScript action. The following example uses a string variable to specify the URL used by a getURL action:

var siteURL = "http://www.flashsupport.com"; getURL(siteURL);

You should start familiarizing yourself with the ActionScript notation that Flash uses for each action (see Table 18-2). As you use Flash for more advanced interactivity, you'll need to have a firm grasp of code notation. Part VII, "Approaching ActionScript," teaches you how to start building more advanced code.

Table 18-2: Common Actions and ActionScript Notation

Action

ActionScript notation

Arguments

gotoAndStop

gotoAndStop(arguments);

Scene Name (Frame Label, Number, or Expression)

gotoAndPlay

gotoAndPlay(arguments);

Scene Name (Frame Label, Number, or Expression)

nextFrame

nextFrame();

None

prevFrame

prevFrame();

None

nextScene

nextScene();

None

prevScene

prevScene();

None

play

play();

None

stop

stop();

None

stopAllSounds

stopAllSounds();

None

getURL

getURL(arguments);

url, target frame or window, method for form submission

Категории