Table of Contents

Chapter 1. A Gentle Introductionfor Nonprogrammers

I'm going to teach you to talk to Flash.

Not just to program in Flash, but to say things to it and listen to what it has to say in return. This is not a metaphor or simply a rhetorical device. It's a philosophical approach to programming.

Programming languages are used to send information to and receive information from computers. They are collections of vocabulary and grammar used to communicate, just like human languages. Using a programming language, we tell a computer what to do or ask it for information. It listens, tries to perform the requested actions, and gives responses. So, while you may think you are reading this book in order to "learn to program," you are actually learning to communicate with Flash. But, of course, Flash doesn't speak English, French, German, or Cantonese. Flash's native language is ActionScript, and you're going to learn to speak it.

Learning to speak a computer language is sometimes considered synonymous with learning to program. But there is more to programming than learning a language's syntax. What would it be like if Flash could speak English�if we didn't need to learn ActionScript in order to communicate with it?

What would happen if we were to say, "Flash, make a ball bounce around the screen?"

Flash couldn't fulfill our request because it doesn't understand the word "ball." Okay, okay, that's just a matter of semantics. What Flash expects us to describe is the objects in the world it knows: movie clips, buttons, frames, and so on. So, let's rephrase our request in terms that Flash recognizes and see what happens: "Flash, make the movie clip named ball_one bounce around the screen."

Flash still can't fulfill our request without more information. How big should the ball be? Where should it be placed? In which direction should it begin traveling? How fast should it go? Around which part of the screen should it bounce? For how long? In two dimensions or three? Hmm . . . we weren't expecting all these questions. In reality, Flash doesn't ask us these questions. Instead, when Flash can't understand us, it just doesn't do what we want it to, or it yields an error message. For now, we'll pretend Flash asked us for more explicit instructions, and reformulate our request as a series of steps:

  1. A ball is a circular movie clip symbol named ball.

  2. A square is a four-sided movie clip symbol named square.

  3. Make a new green ball 50 pixels in diameter.

  4. Call the new ball ball_one.

  5. Make a new black square 300 pixels wide, and place it in the middle of the Stage.

  6. Place ball_one somewhere on top of the square.

  7. Move ball_one in a random direction at 75 pixels per second.

  8. If ball_one hits one of the sides of the square, make it bounce (reverse course).

  9. Continue until I tell you to stop.

Even though we gave our instructions in English, we still had to work through all the logic that governs our bouncing ball in order for Flash to understand us. Obviously, there's more to programming than merely the syntax of programming languages. Just as in English, knowing lots of words doesn't necessarily mean you're a great communicator.

Our hypothetical English-speaking-Flash example exposes four important aspects of programming:

Most programming has nothing to do with writing code. Before you write even a single line of ActionScript, think through exactly what you want to do and write out your system's functionality as a flowchart or a blueprint. Once your program has been described sufficiently at the conceptual level, you can translate it into ActionScript.

In programming�as in love, politics, and business�effective communication is the key to success. For Flash to understand your ActionScript, you have to get your syntax absolutely correct, down to the last quote, equals sign, and semicolon. And to assure that Flash knows what you're talking about, you must refer only to the world it knows using terms it recognizes. What may be obvious to you is not obvious to a computer. Think of programming a computer like talking to a child: take nothing for granted, be explicit in every detail, and list every step that's necessary to complete a task. But remember that, unlike children, Flash will do precisely what you tell it and nothing that you don't.


Table of Contents