ADOBE FLEX 3
Developer Guide
19
Note: Even for those data types that let you create instances using a literal expression, you can still use the new operator
to create an object instance. For instance, these two lines of code do exactly the same thing:
var someNumber:Number = 6.33;
var someNumber:Number = new Number(6.33);
It’s important to be familiar with the new ClassName() way of creating objects. If you need to create an instance of
any ActionScript data type that doesnt have a visual representation (and hence cant be created by placing an item
on the Flash Stage or the Design mode of Flex Builders MXML editor), you can only do so by creating the object
directly in ActionScript using the
new operator.
In Flash specifically, the
new operator can also be used to create an instance of a movie clip symbol that is defined in
the Library but isnt placed on the Stage. For more about this, see Creating MovieClip objects with ActionScript” on
page 350.
Common program elements
In addition to declaring variables, creating object instances, and manipulating objects using their properties and
methods, there are a few other building blocks that you use to create an ActionScript program.
Operators
Operators are special symbols (or occasionally words) that are used to perform calculations. They are mostly used
for math operations, and also used when comparing values to each other. As a general rule, an operator uses one or
more values and “works out” to a single result. For example:
The addition operator (+) adds two values together, resulting in a single number:
var sum:Number = 23 + 32;
The multiplication operator (*) multiplies one value by another, resulting in a single number:
var energy:Number = mass * speedOfLight * speedOfLight;
The equality operator (==) compares two values to see if they are equal, resulting in a single true-or-false
(Boolean) value:
if (dayOfWeek == "Wednesday")
{
takeOutTrash();
}
As shown here, the equality operator and the other “comparison” operators are most commonly used with the
if statement to determine if certain instructions should be carried out or not.
For more details and examples of using operators, see “Operators” on page 63.
Comments
As youre writing ActionScript, youll often want to leave notes to yourself, perhaps explaining how certain lines of
code work or why you made a particular choice. Code comments are a tool you can use to write text that the computer
should ignore in your code. ActionScript includes two kinds of comments:
Single-line comment: A single-line comment is designated by placing two slashes anywhere on a line. Everything
after the slashes up to the end of that line is ignored by the computer:
// This is a comment; it’s ignored by the computer.

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.