Keywords and Statements

Keywords and Statements

One difficulty that arises for nearly everyone when they begin coding is discerning which words in a piece of code have special meanings and which words are simply created by the person writing the code. The words that have special meaning fall into a couple of categories; the largest two cat- egories are keywords and statements. The words contained in

these categories are reserved by Flash for specific purposes.

Animation with Scripting for Adobe Flash Professional CS5 Studio Techniques

Keywords are used either to define entities like variables, functions, and classes, or to alter the meaning of certain definitions. Keywords include class, extends, function, var, get,

set, and so forth. Statements are language elements that perform or specify

an action at runtime (when your movie is playing). For example, the if statement evaluates a condition to deter- mine the next action that should be taken. Statements include if, break, case, while, for, return, and so forth.

You will naturally integrate keywords and statements into your vocabulary over time. As you go through the examples in this chapter, notice which words are used most often and how (or if) the Flash Code Editor highlights them. Gener- ally, words that are reserved by ActionScript appear in dark blue by default in the Code Editor (Figure 3.2).

Changing Code Coloring

You can change the colors used in the Code Editor. To customize ActionScript highlight colors, choose

Figure 3.2 The Flash Code Editor indicates reserved words using Edit > Preferences (or Flash > Preferences on a

different colors.

Mac) and select the ActionScript category at the left. In addition to changing the highlight color

For a complete list of keywords and statements see for keywords, identifiers, strings, and comments,

http://help.adobe.com/en_US/FlashPlatform/reference/ you can change the foreground and background

actionscript/3/statements.html.

colors of the Code Editor (Figure 3.3). If you find

black text on a white screen hard on your eyes, you can try a light gray foreground on dark gray

Operators

background. Operators, just like keywords and statements, are a built-in part of ActionScript. Operators are characters that have symbolic value. Operators allow you to combine, compare, or modify values inside ActionScript. Many of the opera- tors function the same way you would expect them to on

Figure 3.3 ActionScript Code Editor color-

a calculator. Common operators include addition (+),

ing in the ActionScript settings inside the

subtraction (-), division (/), multiplication (*), increment

Flash preferences.

(++), equality (==), less than (<), and so on.

Chapter 3 Introduction to ActionScript Classes

Also, logical operators help you evaluate the truth value of statements. Common logical operators include and (&&), or (||), and not (!). It’s not important to memorize all the operators before continuing with the chapter, just be aware of their usage in the examples that follow.

There are also operators that help you organize your code. Four such operators that you will find in every example within this chapter are curly braces ({}), square brackets ([]), parentheses (()), and the semicolon (;). Let’s exam- ine each of these in detail.