An *operator* is a symbol or keyword that
manipulates, combines, or transforms data. For example, the following
code uses the multiplication operator (`*`

) to multiply 5 times 6:

5 * 6;

Though each operator has its own specialized task, all operators share a number of general characteristics. Before we consider the operators individually, let's see how they behave generally.

Operators perform actions using the data values
(*operands*) supplied. For example, in the
operation `5 * 6`

, the numbers 5 and
6 are the *operands* of the multiplication operator
(`*`

).

Operations can be combined to form complex expressions. For example:

((width * height) - (Math.PI * radius * radius)) / 2

When expressions become very large, consider using variables to hold interim results for both convenience and clarity. Remember to name your variables descriptively. For example, the following code has the same result as the preceding expression but is much easier to read:

var radius:int = 10; var height:int = 25; var circleArea:Number = (Math.PI * radius * radius); var cylinderVolume:Number = circleArea * height;

Operators are sometimes categorized according to how many
operands they take (i.e., require or *operate
on*). Some ActionScript operators take one operand, some
take two, and one even takes three:

-x // One operand x * y // Two operands (x == y) ? "true result" : "false result" // Three operands

Single-operand operators are called *unary* operators; operators that take two operands are called ...

Start Free Trial

No credit card required