9
Chapter 3: Getting started with
ActionScript
This chapter is designed to get you started with ActionScript programming and give you the background youll need
to understand the concepts and examples in the rest of this manual. We’ll begin with a discussion of basic
programming concepts, described in the context of how to apply them in ActionScript. Well also cover the essentials
of how to organize and build an ActionScript application.
Contents
Programming fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Working with objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Common program elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Building applications with ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Creating your own classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Example: Creating a basic application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Running subsequent examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Programming fundamentals
Since ActionScript is a programming language, it will help you learn ActionScript if you first understand a few
general computer programming concepts.
What computer programs do
First of all, it’s useful to have a conceptual idea of what a computer program is and what it does. There are two main
aspects to a computer program:
A program is a series of instructions or steps for the computer to carry out.
Each step ultimately involves manipulating some piece of information or data.
In a general sense, a computer program is just a list of step-by-step instructions that you give to the computer, which
it performs one by one. Each individual instruction is known as a statement. As you’ll see throughout this manual,
in ActionScript, each statement is written with a semicolon at the end.
In essence, all that a given instruction in a program does is manipulate some bit of data thats stored in the computers
memory. In a simple case, you might instruct the computer to add two numbers and store the result in its memory.
In a more complex case, imagine there is a rectangle drawn on the screen, and you want to write a program to move
it somewhere else on the screen. The computer is keeping track of certain information about the rectangle—the x, y
coordinates where it’s located, how wide and tall it is, what color it is, and so forth. Each of those bits of information
is stored somewhere in the computer’s memory. A program to move the rectangle to a different location would have
steps like “change the x coordinate to 200; change the y coordinate to 150” (in other words, specifying new values to
be used for the x and y coordinates). Of course, the computer does something with this data to actually turn those
numbers into the image that appears on the computer screen; but for the level of detail were interested in, its enough
to know that the process of “moving a rectangle on the screen” really just involves changing bits of data in the
computer’s memory.

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.