I'm going to teach you to talk to Flash.
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:
A ball is a circular movie clip symbol named ball.
A square is a four-sided movie clip symbol named
square.
Make a new green ball 50 pixels in diameter.
Call the new ball ball_one.
Make a new black square 300 pixels wide and place it in the middle of
the Stage.
Place ball_one somewhere on top of the square.
Move ball_one in a random direction at 75 pixels
per second.
If ball_one hits one of the sides of the square,
make it bounce (reverse course).
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:
No matter what the language, the art of programming lies in the
formulation of logical steps.
Before you try to say something in a computer language, it usually
helps to say it in English.
A conversation in one language translated into a different language
is still made up of the same basic statements.
Computers aren't very good at making assumptions. They also
have a very limited vocabulary.
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.