|
Actionscript Operators
ActionScript provides a rich set of operators. Operators are used for specifying how we can modify , combine or compare an expression. This chapter describes all ActionScript operators. ActionScript divides its operators into the following groups. Arithmetic operators, Comparison Operators, String operators, logical operators, btiwise operators, equality operators, dot operators
Arithmetic Operators
Arithmetic operators are used in ActionScript in the same way it is used in Algebra. Arithmetic operators are add, subtract, multiply, divide and modulo. The following table lists the arithmetic operators
| + |
Addition |
| - |
Subtraction |
| * |
Multiplication |
| / |
Division |
| % |
Modulus |
| ++ |
Increment |
| -- |
Decrement |
The operands of arithmetic operators must be of type numeric. You cannot apply arithmetic operators on any other types. The modulus operator returns the reminder of a division operation. For eg:
10 % 2 = 0
11 % 2 = 1
Increment and Decrement operators
The ++ and -- are ActionScript increment and decrement operators. The increment operators increases its operands by one. The decrement operator decreases its operand by one. For eg:
x = x+ 1; is equal to
x++;
and x = x-1 is equal to
x--;
The increment and decrement operators can appear in postfix form and prefix form. There is a big difference between the postfix form and prefix form when they appear as part of a big expression. in prefix form the operand is incremented or decremented before the value is obtained for use in the expression and in postfix form first the previous value is obtained and then the operand will be modified.
Comparison Operators
Comparison operates also called as relational operators as it determines the relationship that one operand has to other. The comparison operators compares the values of an expression. The following table lists the comparison or relational operators.
| < |
Less than |
| > |
Greater than |
| <= |
Less than or equal to |
| >= |
Greater than or equal to |
The outcome of comparison operators would be a boolean value. These operates are most widely used in control statements and loop statements.
String Operators
The operates +, >, >=, < , and <= are having a special meaning when it is used with a string. The + operator concatenates two strings. For eg:
"hello" + " world " produces the output "hello world";
The >, >=, <, and <= compares two strings to determine which is first in alphabetical order. This would work only if both the operands are strings. if one operand is not a string, ActionScript converts both the operands to numbers.
Logical Operators
Logical operators operate only on boolean operands. The following table lists the logical operators.
| Operator |
Result |
| && |
AND |
| || |
OR |
| ! |
NOT |
The logical operators operate only on boolean operands and returns a boolean value. If both the operands evaluate to true logical AND (&&) returns true. If any one or both the operators evaluates to true logical OR (||) returns true and the logical NOT (!) inverts a boolean statement.
Bitwise Operators
Bitwise operators operates only on 32-bit integer types. These operators operates on the individual bits of the operands. The following table lists the bitwise operators
| Operator |
Result |
| & |
Bitwise AND |
| | |
Bitwise OR |
| ^ |
Bitwise XOR |
| ~ |
Bitwise NOT |
| << |
Left Shift |
| >> |
Right Shift |
| >>> |
Shift right zero fill |
Equality Operators
Equality operators determines the equality of the operands. The equality operators always returns a boolean value. The following table lists ActionScript equality operators
| Operator |
Result |
| == |
Equality |
| != |
Inequality |
| === |
Strict equality |
| !== |
Strict inequality |
The equality operator compares two operands and evaluates to a boolean value. The strict equality operator also compares two operands and evaluate to a boolean value. The only difference between equality and strict equality operators are if both operand's data types are different the strict equality operator would return false even if the values are same. The strict inequality operator returns the inversion the strict equality operator.
Dot Operators
The do (.)t operator is used for accessing ActionScript object's properties. For eg:
man.height =10;
Here man is the object and height is the property of the object man.
|