User Guide
Operators 77
An error results if you attempt to assign an initial value to a constant in any other way. For
example, if you attempt to set the initial value of
MAXIMUM outside the class, a run-time error
will occur.
class A
{
public const MINIMUM:int = 0;
public const MAXIMUM:int;
}
var a:A = new A();
a["MAXIMUM"] = 10; // run-time error
The Flash Player API defines a wide range of constants for your use. By convention, constants
in ActionScript use all capital letters, with words separated by the underscore character (
_ ).
For example, the MouseEvent class definition uses this naming convention for its constants,
each of which represents an event related to mouse input:
package flash.events
{
public class MouseEvent extends Event
{
public static const CLICK:String = "click";
public static const DOUBLE_CLICK:String = "doubleClick";
public static const MOUSE_DOWN:String = "mouseDown";
public static const MOUSE_MOVE:String = "mouseMove";
...
}
}
Operators
Operators are special functions that take one or more operands and return a value. An operand
is a value—usually a literal, a variable, or an expression—that an operator uses as input. For
example, in the following code, the addition (
+) and multiplication (*) operators are used
with three literal operands (2, 3
, and 4) to return a value. This value is then used by the
assignment (
=) operator to assign the returned value, 14, to the variable sumNumber.
var sumNumber:uint = 2 + 3 * 4; // uint = 14
Operators can be unary, binary, or ternary. A unary operator takes one operand. For example,
the increment (
++) operator is a unary operator because it takes only one operand. A binary
operator takes two operands. For example, the division (
/) operator takes two operands. A
ternary operator takes three operands. For example, the conditional (
?:) operator takes three
operands.