Breaking Down the Interactive Process


Before you can become an ActionScript code warrior, realize that this isn't just a weekend activity — if you want to excel at Flash ActionScripting, you'll need to commit the time and energy necessary for the proper revelations to occur. It's not likely that you'll understand programming simply by reading this chapter (or the whole book). You need to create some trials for yourself, testing your textbook knowledge and applying problem-solving techniques.

You might be thinking, "Oh no, you mean I have to revisit that torture of grade school math?" Not exactly, but programming, like math, requires strong reasoning and justification skills. You need to be able to understand how values (for example, the height of a Movie Clip instance) are determined, what type of changes you can perform on those values, and how changes to one value might affect another value. If you're feeling overwhelmed, don't worry. We take this one step at a time.

Define Your Problems

Regardless of what interactive authoring tool you use (Macromedia Dreamweaver, Macromedia Flash, Macromedia Director, and so on), you can't begin any production work until you have a clear idea of the product. What is it that you are setting out to do? At this point in the process, you should use natural language to describe your problems; that is, define your objective (or problem) in a way that you understand it. For example, let's say that you want to make a quiz. You'll have to run through a list of goals for that interactive product:

  • Is it a true/false test?

  • Or will it be multiple choice?

  • Or how about fill-in-the-blank?

  • Is it an essay test?

  • How many questions will be on the quiz?

  • Will there be a time limit for each question?

  • Will you notify the person of wrong answers?

  • How many chances does the person get to answer correctly?

Other questions, of course, could help define what your product will encompass. Don't try to start Flash production without setting some project parameters for yourself.

Clarify the Solution

After you have defined the boundaries for the project, you can start to map the process with which your product will operate. This step involves the procedure of the experience (in other words, how the person will use the product you are creating). With the quiz example, you might clarify the solution as:

  1. The user starts the movie and types his or her name.

  2. After submitting the name, the user will be told that he or she has 10 minutes to complete a 25-question quiz that's a combination of true/false and multiple-choice questions.

  3. Upon acknowledging the instructions (by pressing a key or clicking a button), the timer starts and the user is presented with the first question.

  4. The timer is visible to the user.

  5. The first question is a true/false question, and the correct answer is False.

  6. If the user enters a True response, a red light graphic appears and the sound of a buzzer plays. The user is asked to continue with the next question.

  7. If the user enters a false response, a green light graphic appears and the sound of applause plays. The user is asked to continue with the next question.

  8. This process repeats until the last question is answered, at which point the score is tallied and presented to the user.

The preceding eight steps are similar to a process flowchart, as we discussed in Chapter 3, "Planning Flash Projects." In real-life production, you would want to clarify Step 8 for each question in the same amount of detail as Steps 5 through 7 did. As you can see, once you start to map the interactive experience, you'll have a much better starting point for your scripting work. Notice that we're already using logic, with our if statements in Steps 6 and 7. We're also determining object properties such as _visible in Step 4. While you may not know all the ActionScript involved with starting a timer, you know that you have to learn how time can be measured in a Flash movie.

Note 

We use the terms scripting, programming, and coding interchangeably through this chapter and other parts of the book.

Translate the Solution into the Interactive Language

After you have created a process for the movie to follow, you can start to convert each step into a format that Flash can use. This step will consume much of your time as you look up concepts and keywords in this book, the Flash ActionScript Bible series by Robert Reinhardt and Joey Lott (Wiley), or Macromedia's updated Help panel that ships with Flash 8. It's likely that you won't be able to find a prebuilt Flash movie example to use as a guide, or if you do, that you'll need to customize it to suit the particular needs of your project. For the quiz example, we could start to translate the solution as:

  • 1. Frame 1: Movie stops. User types name into a text field.

  • 2a. Frame 1: User clicks a submit Button symbol instance to initiate the quiz. The instructions are located on frame 2. Therefore, the Button action uses a gotoAndStop(2) action to move the Playhead to the next frame.

  • 2b. Frame 2: Static text will be shown, indicating the guidelines for the quiz.

  • 3. Frame 2: User clicks a start quiz Button symbol instance. An action on the Button instance starts a timer and moves the Playhead to frame 3.

  • 4. Frame 3: The current time of the timer is displayed in a text field, in the upper-right corner of the Stage.

  • 5. Frame 3: The first question is presented in the center of the Stage. A button with the text True and a button with the text False are located just beneath the question. The correct answer for the question is hidden in a variable name/value. The variable's name is answer, and its value is false. This variable declaration appears as a frame action on frame 3. A variable, called score, will also be declared to keep track of the correct answer count. Its starting value will be 0.

  • 6a. Frame 3: If the user clicks the True button, an if/else action checks whether answer's value is equal to true. If it is, an action sets the _visible of a greenLight_mc Movie Clip instance to true, and initiates and plays a new Sound object for the applause.wav file in your Library. Also, the value of score increases by 1. If the value of answer is not true, then an action sets the _visible of a redLight_mc Movie Clip instance to true, and initiates and plays a new Sound object for the error.wav file in your Library. The value of score will be left as is.

  • 6b. Frame 3: A Button instance appears, and when it's clicked, it takes the user to frame 4.

  • 7a. Frame 3: If the user clicks the False button, an if/else action checks whether answer's value is equal to true. If it is, an action sets the _visible of a greenLight_mc Movie Clip instance to true, and initiates and plays a new Sound object for the applause.wav file in your Library. Also, the value of score increases by 1. If the value of answer is not true, an action sets the _visible of a redLight_mc Movie Clip instance to true and initiates and plays a new Sound object for the error.wav file in your Library. The value of score is left as is.

  • 7b. Frame 3: A Button instance appears, and when it's clicked, it takes the user to frame 4.

Although there is more than one way we could have translated this into ActionScript-like syntax, you'll notice that a few key concepts are presented in the translation: where events occur (frames or buttons), and which elements (for example, Button symbols or Movie Clip instances) are involved.

Most important, you'll notice that we used the same procedure for both the True and the False buttons. Even though we could hardwire the answer directly in the Button actions, we would have to change our Button actions for each question. By placing the same logic within each Button instance, we have only to change the value of the answer variable from frame to frame (or from question to question).

Granted, this example was already translated for you, and 90 percent of your scripting woes will be in the translation process — before you even have a testable Flash movie. You need to learn the basic terminology and syntax of the ActionScript language before you can start to write the scripting necessary for Steps 1 to 7. And that's exactly what the rest of this chapter (and the rest of Part VII) teaches you.

Cross-Reference 

Because the vocabulary of the ActionScript language has become so immense, Robert Reinhardt and Joey Lott have created a separate Bible series, on Flash ActionScript, to thoroughly address the syntax of ActionScript. However, if you are new to scripting and programming, we recommend that you start with our coverage of ActionScript here before reading the Flash ActionScript Bible by Robert Reinhardt and Joey Lott (Wiley).




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net