Home > Articles > Graphics & Web Design > Dreamweaver & Flash

Learning to Program with Flash MX ActionScript

  • Print
  • + Share This
Gary Rosenweig reviews some basic programming concepts in preparation for implementing them in Flash. He teaches about variables, how computers think, what elements make up a program, how conditions and loops make programs flow, how to break a large problem into smaller parts, and how to write bug-free code.
This sample chapter is excerpted from Sams Teach Yourself Flash MX ActionScript in 24 Hours, by Gary Rosenweig.
This chapter is from the book

Programming is both a science and an art. You will need both knowledge of the programming language's syntax and a lot of creativity because there is rarely only one way to write a program. Ten different programmers will write 10 different programs to accomplish the same task.

As you learn ActionScript, you will develop your own style. At first, you will probably pick up the style that I use in this book. But later this will slowly develop as you adapt techniques you invent yourself.

Some basic programming concepts hold true for just about every programming language. Let's review those concepts in this hour before learning the specifics of how they are implemented in Flash.

In this hour, you will:

  • Understand how computers think

  • Find out what elements make up a program

  • Learn about variables

  • See how conditions and loops make programs flow

  • Learn how to break a large problem into smaller parts

  • Find out how to write bug-free code

How Computers Think

Actually, computers don't think at all. They mindlessly follow instructions. They take these instructions very literally.

A Flash script is a list of instructions. However, it is best not to think of them as a list of instructions addressed to the computer but to the Flash runtime environment. Scripts tell Flash what to do.

When you look at a code listing, you can "play computer" by reading the code and predicting what the computer will do each step of the way.

To play computer, you pretend that you are the computer, or more specifically, that you are Flash. You read each line of the program and pretend that it is an instruction that you must carry out.

For instance, if you are supposed to jump from one frame in the Flash movie to another, you imagine that the Flash movie is now on the destination frame and waiting for the next instruction. You then read the next line and follow that instruction.

By playing computer, you can predict what your scripts will do. You can troubleshoot your scripts this way and fix problems in them before you even run the program once. Soon, playing computer will be something that you do naturally as you program. When you write a line of code, you will imagine what Flash will do with that instruction. As you write a whole script, you will constantly be checking your code by doing this.


Computer programs are like onions. Take a Flash movie, for example. It is a .swf file that runs inside the Flash plug-in. The Flash plug-in, in turn, is running inside your Web browser. The Web browser is running as an application inside your computer's operating system. The operating system uses a complex toolbox of programs to do things such as display pixels on the screen; this toolbox is running on the microprocessor inside your computer.

All these levels depend on the ones below; each level must support everything that runs on top of it. This makes for a complex and delicate system.

Fortunately, as an ActionScript programmer, you are shielded from everything but the top layer. You don't have to know how the microprocessor, operating system, or Web browser works. You don't even have to know how Flash works—just what it is capable of doing and how you go about doing it.

  • + Share This
  • 🔖 Save To Your Account