Statements
Contents:
Types of Statements
Statement Syntax
The ActionScript Statements
Statements Versus Actions
Onward!
We saw in earlier chapters how ActionScript stores and manipulates data. Now we'll learn how to do things with that data. We'll give Flash instructions in the form of statements, or phrases of code that instruct the interpreter to perform some task.
To make something happen in Flash -- whether stopping a sound, playing a movie, running a function, or looping some code -- we use a statement. In fact, an ActionScript program can be defined as nothing more than a list of statements that tell the interpreter what we want Flash to do. Here, for example, is an entire ActionScript program, which consists of four statements and tells the interpreter to load a web page into the browser:
var protocol = "http"; // Statement 1 var domain = "www.moock.org"; // Statement 2 var path = "webdesign/flash/"; // Statement 3 getURL(protocol + "://" + domain + "/" + path); // Statement 4
Scripting a movie with ActionScript is simply a matter of attaching statements to frames, movie clips, and buttons. This chapter explores the syntactic makeup of statements and lists the general statement categories. We'll touch on all the ActionScript statements in this chapter, but some of the more important ones will be examined in detail in later chapters.
Types of Statements
Conceptually speaking, there are five core types of statements:
- Statements that control the execution flow of a program
-
loops
conditionals
ifFrameLoaded
- Statements that declare variables
-
var
set
- Statements that declare, call, and return values from functions
-
function
function call
call
return
- Statements that deal with objects
-
with
for . . . in
- Statements that represent a data value
-
any expression (especially expressions with side effects)
These informal categories help us to understand what we can tell the interpreter to do using statements. At first glance, the list may seem fairly limited. However, we'll see that there are many variations of conditionals and loops and that there are thousands of things we can do via function calls. First, let's see how statements are formed.