Symbolic operators are characters that specify how to combine, compare, or modify the values of an expression.
| | Arithmetic |
| | + | addition | Adds numeric expressions. |
| | -- | decrement | Subtracts 1 from the operand. |
| | / | division | Divides expression1 by expression2. |
| | ++ | increment | Adds 1 to an expression. |
| | % | modulo | Calculates the remainder of expression1 divided by expression2. |
| | * | multiplication | Multiplies two numerical expressions. |
| | - | subtraction | Used for negating or subtracting. |
| | Arithmetic compound assignment |
| | += | addition assignment | Assigns expression1 the value of expression1 + expression2. |
| | /= | division assignment | Assigns expression1 the value of expression1 / expression2. |
| | %= | modulo assignment | Assigns expression1 the value of expression1 % expression2. |
| | *= | multiplication assignment | Assigns expression1 the value of expression1 * expression2. |
| | -= | subtraction assignment | Assigns expression1 the value of expression1 - expression2. |
| | Assignment |
| | = | assignment | Assigns the value of expression2 (the operand on the right) to the variable, array element, or property in expression1. |
| | Bitwise |
| | & | bitwise AND | Converts expression1 and expression2 to 32-bit unsigned integers, and performs a Boolean AND operation on each bit of the integer parameters. |
| | << | bitwise left shift | Converts expression1 and shiftCount to 32-bit integers, and shifts all the bits in expression1 to the left by the number of places specified by the integer resulting from the conversion of shiftCount. |
| | ~ | bitwise NOT | Converts expression to a 32-bit signed integer, and then applies a bitwise one's complement. |
| | | | bitwise OR | Converts expression1 and expression2 to 32-bit unsigned integers, and places a 1 in each bit position where the corresponding bits of either expression1 or expression2 are 1. |
| | >> | bitwise right shift | Converts expression and shiftCount to 32-bit integers, and shifts all the bits in expression to the right by the number of places specified by the integer that results from the conversion of shiftCount. |
| | >>> | bitwise unsigned right shift | The same as the bitwise right shift (>>) operator except that it does not preserve the sign of the original expression because the bits on the left are always filled with 0. |
| | ^ | bitwise XOR | Converts expression1 and expression2 to 32-bit unsigned integers, and places a 1 in each bit position where the corresponding bits in expression1 or expression2, but not both, are 1. |
| | Bitwise compound assignment |
| | &= | bitwise AND assignment | Assigns expression1 the value of expression1 & expression2. |
| | <<= | bitwise left shift and assignment | Performs a bitwise left shift (<<=) operation and stores the contents as a result in expression1. |
| | |= | bitwise OR assignment | Assigns expression1 the value of expression1 | expression2. |
| | >>= | bitwise right shift and assignment | Performs a bitwise right-shift operation and stores the result in expression. |
| | >>>= | bitwise unsigned right shift and assignment | Performs an unsigned bitwise right-shift operation and stores the result in expression. |
| | ^= | bitwise XOR assignment | Assigns expression1 the value of expression1 ^ expression2. |
| | Comment |
| | /*..*/ | block comment delimiter | Delimits one or more lines of script comments. |
| | // | line comment delimiter | Indicates the beginning of a script comment. |
| | Comparison |
| | == | equality | Tests two expressions for equality. |
| | > | greater than | Compares two expressions and determines whether expression1 is greater than expression2; if it is, the result is true. |
| | >= | greater than or equal to | Compares two expressions and determines whether expression1 is greater than or equal to expression2 (true) or expression1 is less than expression2 (false). |
| | != | inequality | Tests for the exact opposite of the equality (==) operator. |
| | < | less than | Compares two expressions and determines whether expression1 is less than expression2; if so, the result is true. |
| | <= | less than or equal to | Compares two expressions and determines whether expression1 is less than or equal to expression2; if it is, the result is true. |
| | === | strict equality | Tests two expressions for equality, but does not perform automatic data conversion. |
| | !== | strict inequality | Tests for the exact opposite of the strict equality (===) operator. |
| | Logical |
| | && | logical AND | Returns expression1 if it is false or can be converted to false, and expression2 otherwise. |
| | ! | logical NOT | Inverts the Boolean value of a variable or expression. |
| | || | logical OR | Returns expression1 if it is true or can be converted to true, and expression2 otherwise. |
| | Other |
| | [] | array access | Initializes a new array or multidimensional array with the specified elements (a0, and so on), or accesses elements in an array. |
| | | as | Evaluates whether an expression specified by the first operand is a member of the data type specified by the second operand. |
| | , | comma | Evaluates expression1, then expression2, and so on. |
| | ?: | conditional | Evaluates expression1, and if the value of expression1 is true, the result is the value of expression2; otherwise the result is the value of expression3. |
| | | delete | Destroys the object property specified by reference; the result is true if the property does not exist after the operation completes, and false otherwise. |
| | . | dot | Accesses class variables and methods, gets and sets object properties, and delimits imported packages or classes. |
| | | in | Evaluates whether a property is part of a specific object. |
| | | instanceof | Evaluates whether an expression's prototype chain includes the prototype object for function. |
| | | is | Evaluates whether an object is compatible with a specific data type, class, or interface. |
| | :: | name qualifier | Identifies the namespace of a property, a method, an XML property, or an XML attribute. |
| | | new | Instantiates a class instance. |
| | {} | object initializer | Creates a new object and initializes it with the specified name and value property pairs. |
| | () | parentheses | Performs a grouping operation on one or more parameters, performs sequential evaluation of expressions, or surrounds one or more parameters and passes them as arguments to a function that precedes the parentheses. |
| | / | RegExp delimiter | When used before and after characters, indicates that the characters have a literal value and are considered a regular expression (RegExp), not a variable, string, or other ActionScript element. |
| | : | type | Used for assigning a data type; this operator specifies the variable type, function return type, or function parameter type. |
| | | typeof | Evaluates expression and returns a string specifying the expression's data type. |
| | | void | Evaluates an expression and then discards its value, returning undefined. |
| | String |
| | + | concatenation | Concatenates (combines) strings. |
| | += | concatenation assignment | Assigns expression1 the value of expression1 + expression2. |
| | " | string delimiter | When used before and after characters, indicates that the characters have a literal value and are considered a string, not a variable, numerical value, or other ActionScript element. |
| | XML |
| | @ | attribute identifier | Identifies attributes of an XML or XMLList object. |
| | { } | braces (XML) | Evaluates an expression that is used in an XML or XMLList initializer. |
| | [ ] | brackets (XML) | Accesses a property or attribute of an XML or XMLList object. |
| | + | concatenation (XMLList) | Concatenates (combines) XML or XMLList values into an XMLList object. |
| | += | concatenation assignment (XMLList) | Assigns expression1, which is an XMLList object, the value of expression1 + expression2. |
| | | delete (XML) | Deletes the XML elements or attributes specified by reference. |
| | .. | descendant accessor | Navigates to descendant elements of an XML or XMLList object, or (combined with the @ operator) finds matching attributes of descendants. |
| | . | dot (XML) | Navigates to child elements of an XML or XMLList object, or (combined with the @ operator) returns attributes of an XML or XMLList object. |
| | ( ) | parentheses (XML) | Evaluates an expression in an E4X XML construct. |
| | < > | XML literal tag delimiter | Defines an XML tag in an XML literal. |
Usage
| expression1 + expression2 |
Adds numeric expressions. If both expressions are integers, the sum is an integer; if either or both expressions are floating-point numbers, the sum is a floating-point number.
If one expression is a string, all other expressions are converted to strings and concatenated instead of summed. Otherwise, if an expression is not a number, Flash® Player converts it to a number.
Operands
| expression1:Number —
A value to be added.
|
| expression2:Number —
A value to be added.
|
Result
| Number — An integer or floating-point number. |
Example
How to use examples
This statement adds the integers 2 and 3:
This statement adds the floating-point numbers 2.5 and 3.25:
trace(2.5 + 3.25); // 5.75
This example shows that if one expression is a string, all other expressions are converted to strings and concatenated:
trace("Number " + 8 + 0); // Number 80
Variables associated with dynamic and input text fields have the data type String. In the following example, the variable deposit is an input text field on the Stage. After a user enters a deposit amount, the script attempts to add deposit to oldBalance. However, because deposit is of type String, the script concatenates (combines to form one string) the variable values rather than summing them.
var oldBalance:Number = 1345.23;
var currentBalance = deposit_txt.text + oldBalance;
trace(currentBalance);
For example, if a user enters 475 in the deposit text field, the trace() statement sends the value 4751345.23 to the Output panel. To correct this, use the Number() function to convert the string to a number, as shown here:
var oldBalance:Number = 1345.23;
var currentBalance:Number = Number(deposit_txt.text) + oldBalance;
trace(currentBalance);
See also
Usage
| expression1 += expression2 |
Assigns expression1 the value of expression1 + expression2. For example, the following two statements have the same result:
x += y;
x = x + y;
All the rules of the addition (+) operator apply to the addition assignment (
+=) operator.
Operands
| expression1:Number —
A number.
|
| expression2:Number —
A number.
|
Result
| Number — The result of the addition. |
Example
How to use examples
The following example shows a numeric use of the addition assignment (
+=) operator:
var x:Number = 5;
var y:Number = 10;
x += y;
trace(x); // 15
See also
Usage
| myArray = [a0, a1,...aN]
myArray[i] = value
myObject[propertyName]
|
| Player Version : | Flash Player 9 |
Initializes a new array or multidimensional array with the specified elements (a0, and so on), or accesses elements in an array. The array access operator lets you dynamically set and retrieve instance, variable, and object names. It also lets you access object properties.
Usage 1: An array is an object whose properties are called elements, which are each identified by a number called an index. When you create an array, you surround the elements with the array access ([]) operator (or brackets). An array can contain elements of various types. For example, the following array, called employee, has three elements; the first is a number and the second two are strings (inside quotation marks):
var employee:Array = [15, "Barbara", "Jay"];
You can nest brackets to simulate multidimensional arrays. You can nest arrays up to 256 levels deep. The following code creates an array called
ticTacToe with three elements; each element is also an array with three elements:
var ticTacToe:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
/* Select Debug > List Variables in test mode
to see a list of the array elements.*/
Usage 2: Surround the index of each element with brackets ([]) to access it directly; you can add a new element to an array, or you can change or retrieve the value of an existing element. The first index in an array is always 0, as shown in the following example:
var my_array:Array = new Array();
my_array[0] = 15;
my_array[1] = "Hello";
my_array[2] = true;
You can use brackets to add a fourth element, as shown in the following example:
You can use brackets to access an element in a multidimensional array. The first set of brackets identifies the element in the original array, and the second set identifies the element in the nested array. The following
trace() statement finds the third element (index 2) of the second array (index 1).
var ticTacToe:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
trace(ticTacToe[1][2]); // 6
Usage 3: You can use the array access operator to dynamically set and retrieve values for a property of an object:
var obj:Object = new Object();
obj.prop1 = "foo";
trace(obj["prop" + 1]); // foo
obj.prop2 = "bar";
for (j in obj) {
trace(obj[j]);
}
/* Output of for loop:
foo
bar */
Operands
| myArray:Object —
The name of an array.
|
| a0, a1,...aN:Object —
Elements in an array; any native type or object instance, including nested arrays.
|
| i:Number —
An integer index greater than or equal to 0.
|
| myObject:Object —
The name of an object.
|
| propertyName:String —
A string that names a property of the object.
|
Result
| Object — Usage 1: A reference to an array. Usage 2: A value from the array; either a native type or an object instance (including an Array instance). Usage 3: A property from the object; either a native type or an object instance (including an Array instance). |
Example
How to use examples
The following example shows two ways to create a new empty Array object; the first line uses brackets:
var my_array:Array = [];
var my_array:Array = new Array();
The following example creates an array called employee_array with three elements and changes the third element in the array.
var employee_array = ["Barbara", "George", "Mary"];
trace(employee_array); // Barbara,George,Mary
employee_array[2] = "Sam";
trace(employee_array); // Barbara,George,Sam
In the following example, the expression inside the brackets is evaluated, and the result is used as the name of the variable to be retrieved from the
obj object:
var obj:Object = new Object();
obj.prop1 = "foo";
obj.prop2 = "bar";
for (var i:int = 1;i < 3;i++) {
trace(obj["prop"+i]);
}
/* Output of for loop:
foo
bar */
See also
Usage
Evaluates whether an expression specified by the first operand is a member of the data type specified by the second operand. If the first operand is a member of the data type, the result is the first operand. Otherwise, the result is the value null.
The expression used for the second operand must evaluate to a data type.
Operands
| expression:* —
The value to check against the data type specified.
|
| datatype:Class —
The data type used to evaluate the expression operand. The special * type, which means untyped, cannot be used.
|
Result
| Object — The result is expression if expression is a member of the data type specified in datatype. Otherwise, the result is the value null. |
Example
How to use examples
The following example creates a simple array named
myArray and uses the
as operator with various data types.
public var myArray:Array = ["one", "two", "three"];
trace(myArray as Array); // one,two,three
trace(myArray as Number); // null
trace(myArray as int); // null
See also
Usage
| expression1 = expression2 |
Assigns the value of expression2 (the operand on the right) to the variable, array element, or property in expression1. Assignment can be either by value or by reference. Assignment by value copies the actual value of expression2 and stores it in expression1. Assignment by value is used when expression2 is a primitive value, which means that its data type is either Boolean, Number, int, uint, or String. Assignment by reference stores a reference to expression2 in expression1. Assignment by reference is commonly used with the new operator. The new operator creates an object in memory, and a reference to that location in memory is assigned to a variable.
Note: In ActionScript 3.0 all values (including primitive values) are objects, and all assignment is done by reference, but primitive objects have special operators that allow them to behave as if they are assigned by value.
Operands
| expression1:* —
A variable, element of an array, or property of an object.
|
| expression2:* —
A value of any type.
|
Result
| Object — The assigned value, expression2. |
Example
How to use examples
The following example uses assignment by value to assign the value of 5 to the variable
z.
The following example uses assignment by value to assign the value "
hello" to the variable
z:
var x:String;
x = "hello";
The following example uses assignment by reference to create the
moonsOfJupiter variable, which contains a reference to a newly created Array object. Assignment by value is then used to copy the value "Callisto" to the first element of the array referenced by the variable
moonsOfJupiter:
var moonsOfJupiter:Array = new Array();
moonsOfJupiter[0] = "Callisto";
The following example uses assignment by reference to create a new object and assign a reference to that object to the variable
mercury. Assignment by value is then used to assign the value of 3030 to the
diameter property of the
mercury object:
var mercury:Object = new Object();
mercury.diameter = 3030; // in miles
trace(mercury.diameter); // 3030
The following example builds on the previous example by creating a variable named
merkur (the German word for
mercury) and assigning it the value of
mercury. This creates two variables that reference the same object in memory, which means you can use either variable to access the object's properties. You can then change the
diameter property to use kilometers instead of miles:
var merkur:Object = mercury;
merkur.diameter = 4878; // in kilometers
trace(mercury.diameter); // 4878
See also
Usage
Identifies attributes of an XML or XMLList object. For example, myXML.@id
identifies attributes named id for the myXML XML object. You can
also use the following syntax to access
attributes: myXML.attribute("id"), myXML["@id"], and
myXML.@["id"]. The syntax myXML.@id is
recommended. To return an XMLList object of all attribute names, use @*.
To return an attribute with a name that matches an ActionScript reserved word,
use the attribute() method instead of the @ operator.
Operands
| attributeName:* —
The name of the attribute.
|
Example
How to use examples
The first example shows how to use the
@ (at sign) operator to identify an attribute of an element:
var myXML:XML =
<item id = "42">
<catalogName>Presta tube</catalogName>
<price>3.99</price>
</item>;
trace(myXML.@id); // 42
The next example returns all attribute names:
var xml:XML =<example id='123' color='blue'/>
var xml2:XMLList = xml.@*;
trace(xml2 is XMLList); // true
trace(xml2.length()); // 2
for (var i:int = 0; i < xml2.length(); i++)
{
trace(typeof(xml2[i])); // xml
trace(xml2[i].nodeKind()); // attribute
trace(xml2[i].name()); // id and color
}
The next example returns an attribute with a name that matches a reserved word in ActionScript.
You cannot use the syntax
xml.@class (since
class is a reserved word in ActionScript).
You need to use the syntax
xml.attribute("class"):
var xml:XML = <example class='123'/>
trace(xml.attribute("class"));
See also
Usage
| expression1 & expression2 |
Converts expression1 and expression2 to 32-bit unsigned integers,
and performs a Boolean AND operation on each bit of the integer parameters.
Floating-point numbers are converted to integers by discarding any digits after the decimal point.
The result is a new 32-bit integer.
A positive integer is converted to an unsigned hexadecimal value with a maximum value of 4294967295 or 0xFFFFFFFF;
a value larger than the maximum has its most significant digits discarded when it is converted so the value is still 32-bit.
A negative number is converted to an unsigned hexadecimal value using the two's complement notation, with a minimum value of -2147483648 or 0x800000000;
a number less than the minimum is converted to two's complement with greater precision before the most significant digits are discarded.
The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.
Operands
| expression1:Number —
A number or expression that evaluates to a number.
|
| expression2:Number —
A number or expression that evaluates to a number.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following example performs a bitwise AND of 13 (binary 1101) and 11 (binary 1011) by comparing the bit representations of the numbers. The resulting integer is composed of a sequence of bits, each of which is set to 1 only if the bits of both operands at the same position are 1.
var insert:Number = 13;
var update:Number = 11;
trace(insert & update); // 9 (or 1001 binary)
The bitwise AND of 13 (binary 1101) and 11 (binary 1011) is 9 because only the first and last positions in both numbers have the number 1.
1101
& 1011
----
1001
The following examples show the behavior of the return value conversion:
trace(0xFFFFFFFF); // 4294967295
trace(0xFFFFFFFF & 0xFFFFFFFF); // -1
trace(0xFFFFFFFF & -1); // -1
trace(4294967295 & -1); // -1
trace(4294967295 & 4294967295); // -1
See also
Usage
| expression1 &= expression2 |
Assigns expression1 the value of expression1 & expression2. For example, the following two expressions are equivalent:
x &= y;
x = x & y;
Operands
| expression1:Number —
A number or expression that evaluates to a number.
|
| expression2:Number —
A number or expression that evaluates to a number.
|
Result
| int — The value of expression1 & expression2. |
Example
How to use examples
The following example assigns the value 9 to
x:
var x:Number = 15;
var y:Number = 9;
trace(x &= y); // 9
See also
Usage
| expression1 << shiftCount |
Converts expression1 and shiftCount to 32-bit integers, and shifts all the bits in expression1 to the left by the number of places specified by the integer resulting from the conversion of shiftCount. The bit positions that are emptied as a result of this operation are filled in with 0 and bits shifted off the left end are discarded. Shifting a value left by one position is the equivalent of multiplying it by 2.
A floating-point number is converted to an integer by discarding any digits after the decimal point.
A positive integer is converted to an unsigned hexadecimal value with a maximum value of 4294967295 or 0xFFFFFFFF;
a value larger than the maximum has its most significant digits discarded when it is converted so the value is still 32-bit.
A negative number is converted to an unsigned hexadecimal value using the two's complement notation, with a minimum value of -2147483648 or 0x800000000;
a number less than the minimum is converted to two's complement with greater precision before the most significant digits are discarded.
The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.
If the result is a negative integer, a runtime error occurs if you attempt to assign the result to a variable of type uint. Although ActionScript has no "unsigned bitwise left shift" operator, you can achieve the same effect, and avoid the runtime error, by using uint(expression1 << shiftCount):
var num1:uint = 0xFF;
var num2:uint = uint(num1 << 24); // uint() prevents runtime error
Operands
| expression1:Number —
A number or expression to be shifted left.
|
| shiftCount:Number —
A number or expression that converts to an integer from 0 to 31.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
In the following example, the integer 1 is shifted 10 bits to the left:
The result of the bitwise left shift operation is 1024. This is because 1 decimal equals 1 binary, 1 binary shifted left by 10 is 10000000000 binary, and 10000000000 binary is 1024 decimal:
00000000001 binary
<< 10 decimal
--------------
10000000000 binary equals 1024 decimal
In the following example, the integer 7 is shifted 8 bits to the left:
The result of the bitwise left shift operation is 1792. This is because 7 decimal equals 111 binary, 111 binary shifted left by 8 bits is 11100000000 binary, and 11100000000 binary is 1792 decimal:
00000000111 binary
<< 8 decimal
--------------
11100000000 binary equals 1792 decimal
The following trace statement shows that the bits have been pushed three positions to the left:
// 1 binary == 0001
// 8 binary == 1000
trace(1 << 3); // 8
See also
Usage
| expression1 <<= expression2 |
Performs a bitwise left shift (<<=) operation and stores the contents as a result in expression1. The following two expressions are equivalent:
A <<= B
A = (A << B)
Operands
| expression1:Number —
A number or expression to be shifted left.
|
| expression2:Number —
A number or expression that converts to an integer from 0 to 31.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following example uses the bitwise left shift and assignment (<<=) operator to shift all bits one position to the left:
var x:Number = 4;
// Shift all bits one slot to the left.
x <<= 1;
trace(x); // 8
// 4 decimal = 0100 binary
// 8 decimal = 1000 binary
See also
Usage
Converts expression to a 32-bit signed integer, and then applies a bitwise one's complement. That is, every bit that is a 0 is set to 1 in the result, and every bit that is a 1 is set to 0 in the result. The result is a signed 32-bit integer.
This operator is also known as the one's complement operator or the bitwise complement operator.
For example, the hexadecimal value 0x7777 is represented as this binary number:
0111011101110111
The bitwise negation of that hexadecimal value, ~0x7777, is this binary number:
1000100010001000
In hexadecimal, this is 0x8888. Therefore, ~0x7777 is 0x8888.
The most common use of bitwise operators is for representing flag bits (Boolean values packed into 1 bit each).
A floating-point number is converted to an integer by discarding any digits after the decimal point.
A positive integer is converted to an unsigned hexadecimal value with a maximum value of 4294967295 or 0xFFFFFFFF;
a value larger than the maximum has its most significant digits discarded when it is converted so the value is still 32-bit.
A negative number is converted to an unsigned hexadecimal value using the two's complement notation, with a minimum value of -2147483648 or 0x800000000;
a number less than the minimum is converted to two's complement with greater precision before the most significant digits are discarded.
The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.
Operands
| expression:Number —
A number to be converted.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following example demonstrates a use of the bitwise NOT (
~) operator with flag bits:
var ReadOnlyFlag:int = 0x0001; // defines bit 0 as the read-only flag
var flags:int = 0;
trace(flags);
/* To set the read-only flag in the flags variable,
the following code uses the bitwise OR:
*/
flags |= ReadOnlyFlag;
trace(flags);
/* To clear the read-only flag in the flags variable,
first construct a mask by using bitwise NOT on ReadOnlyFlag.
In the mask, every bit is a 1 except for the read-only flag.
Then, use bitwise AND with the mask to clear the read-only flag.
The following code constructs the mask and performs the bitwise AND:
*/
flags &= ~ReadOnlyFlag;
trace(flags);
// 0 1 0
See also
Usage
| expression1 | expression2 |
Converts expression1 and expression2 to 32-bit unsigned integers, and places a 1 in each bit position where the corresponding bits of either expression1 or expression2 are 1.
A floating-point number is converted to an integer by discarding any digits after the decimal point.
A positive integer is converted to an unsigned hexadecimal value with a maximum value of 4294967295 or 0xFFFFFFFF;
a value larger than the maximum has its most significant digits discarded when it is converted so the value is still 32-bit.
A negative number is converted to an unsigned hexadecimal value using the two's complement notation, with a minimum value of -2147483648 or 0x800000000;
a number less than the minimum is converted to two's complement with greater precision before the most significant digits are discarded.
The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.
Operands
| expression1:Number —
A number.
|
| expression2:Number —
A number.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following is an example of a bitwise OR (
|) operation:
// 15 decimal = 1111 binary
var a:Number = 15;
// 9 decimal = 1001 binary
var b:Number = 9;
// 1111 | 1001 = 1111
trace(a | b); // returns 15 decimal (1111 binary)
Don't confuse the single
| (bitwise OR) with
|| (logical OR).
See also
Usage
| expression1 |= expression2 |
Assigns expression1 the value of expression1 | expression2. For example, the following two statements are equivalent:
x |= y;
x = x | y;
Operands
| expression1:Number —
A number to be converted.
|
| expression2:Number —
A number to be converted.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following example uses the bitwise OR assignment (
|=) operator:
// 15 decimal = 1111 binary
var a:Number = 15;
// 9 decimal = 1001 binary
var b:Number = 9;
// 1111 |= 1001 = 1111
trace(a |= b); // returns 15 decimal (1111 binary)
See also
Usage
Converts expression and shiftCount to 32-bit integers, and shifts all the bits in expression to the right by the number of places specified by the integer that results from the conversion of shiftCount. Bits that are shifted off the right end are discarded. To preserve the sign of the original expression, the bits on the left are filled in with 0 if the most significant bit (the bit farthest to the left) of expression is 0, and filled in with 1 if the most significant bit is 1. Shifting a value right by one position is the equivalent of dividing by 2 and discarding the remainder.
A floating-point number is converted to an integer by discarding any digits after the decimal point.
A positive integer is converted to an unsigned hexadecimal value with a maximum value of 4294967295 or 0xFFFFFFFF;
a value larger than the maximum has its most significant digits discarded when it is converted so the value is still 32-bit.
A negative number is converted to an unsigned hexadecimal value using the two's complement notation, with a minimum value of -2147483648 or 0x800000000;
a number less than the minimum is converted to two's complement with greater precision before the most significant digits are discarded.
The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.
Operands
| expression:Number —
A number or expression to be shifted right.
|
| shiftCount:Number —
A number or expression that converts to an integer from 0 to 31.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following example converts 65535 to a 32-bit integer and shifts it 8 bits to the right, resulting in a decimal value of 255:
var a:Number = 65535 >> 8;
trace(a); // 255
This is because 65535 decimal equals 00000000000000001111111111111111 binary (sixteen 0s followed by sixteen 1s); shifting right by 8 bits causes the 8 least significant bits (the bits farthest to the right) to be discarded. Because 65535 is positive, the bit position made available by the shift (the 8 bit positions farthest on the left) are filled in with 0s. The result is 00000000000000000000000011111111 (twenty-four 0s followed by eight 1s) binary, which represents the 32-bit integer 255.
00000000000000001111111111111111 binary (65535 decimal)
>> 8 decimal
--------------------
00000000000000000000000011111111 binary (255 decimal)
The following example converts -8 to a 32-bit integer and shifts it 1 bit to the right, resulting in a decimal value of -4:
var a:Number = -8 >> 1;
trace(a); // -4
This is because -8 decimal equals 11111111111111111111111111111000 binary (twenty-nine 1s followed by three 0s); shifting right by one bit causes the least significant bit (the bit farthest to the right) to be discarded. Because -8 is negative, the bit position made available by the shift (the 1 bit position farthest on the left) is filled in with 1. The result is 11111111111111111111111111111100 (thirty 1s followed by two 0s) binary, which represents the 32-bit integer -4.
11111111111111111111111111111000 binary (-8 decimal)
>> 1 decimal
--------------------
11111111111111111111111111111100 binary (-4 decimal)
See also
Usage
| expression >>= shiftCount |
Performs a bitwise right-shift operation and stores the result in expression.
The following two statements are equivalent:
A >>= B;
A = (A >> B);
Operands
| expression:Number —
A number or expression to be shifted right.
|
| shiftCount:Number —
A number or expression that converts to an integer from 0 to 31.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following code uses the bitwise right shift and assignment (
>>=) operator:
function convertToBinary(numberToConvert:Number):String {
var result:String = "";
for (var i = 0; i < 32; i++) {
// Extract least significant bit using bitwise AND.
var lsb:Number = numberToConvert & 1;
// Add this bit to the result.
result = (lsb ? "1" : "0")+result;
// Shift numberToConvert right by one bit, to see next bit.
numberToConvert >>= 1;
}
return result;
}
trace(convertToBinary(479));
// Returns the string 00000000000000000000000111011111.
// This string is the binary representation of the decimal number 479.
See also
Usage
| expression >>> shiftCount |
The same as the bitwise right shift (>>) operator except that it does not preserve the sign of the original expression because the bits on the left are always filled with 0.
A floating-point number is converted to an integer by discarding any digits after the decimal point.
A positive integer is converted to an unsigned hexadecimal value with a maximum value of 4294967295 or 0xFFFFFFFF;
a value larger than the maximum has its most significant digits discarded when it is converted so the value is still 32-bit.
A negative number is converted to an unsigned hexadecimal value using the two's complement notation, with a minimum value of -2147483648 or 0x800000000;
a number less than the minimum is converted to two's complement with greater precision before the most significant digits are discarded.
The result is interpreted as a 32-bit unsigned integer, so the result is an integer in the range 0 to 4294967295.
Note: ActionScript has no complementary "bitwise unsigned left shift" operator, but you can achieve the same effect by using uint(expression << shiftCount).
Operands
| expression:Number —
A number or expression to be shifted right.
|
| shiftCount:Number —
A number or expression that converts to an integer between 0 and 31.
|
Result
| uint — The result of the bitwise operation. |
Example
How to use examples
The following example converts -1 to a 32-bit integer and shifts it 1 bit to the right:
var a:Number = -1 >>> 1;
trace(a); // 2147483647
This is because -1 decimal is 11111111111111111111111111111111 binary (thirty-two 1s), and when you shift right (unsigned) by 1 bit, the least significant (rightmost) bit is discarded, and the most significant (leftmost) bit is filled with a 0. The result is 01111111111111111111111111111111 binary, which represents the 32-bit integer 2147483647.
See also
Usage
| expression >>>= shiftCount |
Performs an unsigned bitwise right-shift operation and stores the result in expression. The following two statements are equivalent:
A >>>= B;
A = (A >>> B);
Operands
| expression:Number —
A number or expression to be shifted right.
|
| shiftCount:Number —
A number or expression that converts to an integer from 0 to 31.
|
Result
| uint — The result of the bitwise operation. |
Example
How to use examples
The following example converts -1 to a 32-bit integer and shifts it 1 bit to the right:
var a:Number = -1;
a >>>= 1;
trace(a); // 2147483647
This is because -1 decimal is 11111111111111111111111111111111 binary (thirty-two 1s), and when you shift right (unsigned) by 1 bit, the least significant (rightmost) bit is discarded, and the most significant (leftmost) bit is filled with a 0. The result is 01111111111111111111111111111111 binary, which represents the 32-bit integer 2147483647.
See also
Usage
| expression1 ^ expression2 |
Converts expression1 and expression2 to 32-bit unsigned integers, and places a 1 in each bit position where the corresponding bits in expression1 or expression2, but not both, are 1.
A floating-point number is converted to an integer by discarding any digits after the decimal point.
A positive integer is converted to an unsigned hexadecimal value with a maximum value of 4294967295 or 0xFFFFFFFF;
a value larger than the maximum has its most significant digits discarded when it is converted so the value is still 32-bit.
A negative number is converted to an unsigned hexadecimal value using the two's complement notation, with a minimum value of -2147483648 or 0x800000000;
a number less than the minimum is converted to two's complement with greater precision before the most significant digits are discarded.
The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.
Operands
| expression1:Number —
A number or expression that evaluates to a number.
|
| expression2:Number —
A number or expression that evaluates to a number.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following example uses the bitwise XOR operator on the decimals 15 and 9, and assigns the result to the variable
a:
// 15 decimal = 1111 binary
// 9 decimal = 1001 binary
var a:Number = 15 ^ 9;
trace(a);
// 1111 ^ 1001 = 0110
// returns 6 decimal (0110 binary)
See also
Usage
| expression1 ^= expression2 |
Assigns expression1 the value of expression1 ^ expression2. For example, the following two statements are equivalent:
x ^= y
x = x ^ y
Operands
| expression1:Number —
A number or expression that evaluates to a number.
|
| expression2:Number —
A number or expression that evaluates to a number.
|
Result
| int — The result of the bitwise operation. |
Example
How to use examples
The following example shows a bitwise XOR assignment (^=) operation:
// 15 decimal = 1111 binary
var a:Number = 15;
// 9 decimal = 1001 binary
var b:Number = 9;
trace(a ^= b); // returns 6 decimal (0110 binary)
See also
Usage
| /* comment */ /* comment comment */ |
Delimits one or more lines of script comments. Characters that appear between the opening delimiter (/*) and the closing delimiter (*/) are interpreted as a comment and ignored by the ActionScript compiler.
Use these delimiters to identify comments on multiple successive lines; for single-line comments, use the // delimiter.
You will receive an error message if you omit the closing block comment delimiter (*/), or if you attempt to nest comments.
After an opening delimiter (/*) is used, the first closing delimiter (*/) ends the comment, regardless of the number of opening delimiters placed before it.
Operands
| comment:* —
Any characters.
|
Example
How to use examples
The following script uses block comment delimiters at the beginning of the script:
/* records the X and Y positions of
the ball and bat movie clips */
var ballX:Number = ball_mc._x;
var ballY:Number = ball_mc._y;
var batX:Number = bat_mc._x;
var batY:Number = bat_mc._y;
The following attempt to nest comments results in an error message:
/* This is an attempt to nest comments.
/* But the first closing tag will be paired
with the first opening tag */
and this text will not be interpreted as a comment */
See also
Usage
| myXML = <{tagName} {attributeName} = {attributeValue}>{content}</{tagName}> |
Evaluates an expression that is used in an XML or XMLList initializer.
An XML or XMLList initializer is a literal value that is assigned to a variable of type XML or XMLList.
An expression that is delimited by the XML { and } operators
can be used in an XML or XMLList initializer instead of literal names or values.
An expression can be used in place of tagName, attributeName, attributeValue, and content.
Operands
| myXML:* —
An XML or XMLList object.
|
| tagName:* —
An expression that evaluates to the name of an XML tag.
|
| attributeName:* —
An expression that evaluates to the name of an XML attribute.
|
| attributeValue:* —
An expression that evaluates to the value of an XML attribute.
|
| content:* —
An expression that evaluates to the contents of an XML tag.
|
Example
How to use examples
The following example shows how to use the { and } operators when defining an XML literal:
var tagname:String = "item";
var attributename:String = "id";
var attributevalue:String = "5";
var content:String = "Chicken";
var x:XML = <{tagname} {attributename}={attributevalue}>{content}</{tagname}>;
trace(x.toXMLString()); // <item id="5">Chicken</item>
See also
Usage
Accesses a property or attribute of an XML or XMLList object. The brackets operator allows you to access property names that are not accessible with the dot (.) operator.
Operands
| myXML:* —
An XML or XMLList object.
|
| expression:* —
An expression that evaluates to the name of an XML tag or attribute.
|
Example
How to use examples
The following example shows how to use the
[ and
] operators to access an XML property that is not accessible with the dot operator because of the hyphen in the tag name:
var myXML:XML = <a><foo-bar>44</foo-bar></a>;
trace(myXML["foo-bar"]);
See also
Usage
| (expression1, expression2[, expressionN... ]) |
Evaluates expression1, then expression2, and so on. This operator is primarily used with the for loop statement and is often used with the parentheses () operator.
Operands
| expression1:* —
An expression to be evaluated.
|
| expression2:* —
An expression to be evaluated.
|
| expressionN:* —
Any number of additional expressions to be evaluated.
|
Result
| Object — The values of the evaluated expressions. |
Example
How to use examples
The following example uses the comma (
,) operator in a
for loop:
for (i = 0, j = 0; i < 3 && j < 3; i++, j+=2) {
trace("i = " + i + ", j = " + j);
}
// output:
// i = 0, j = 0
// i = 1, j = 2
The following example uses the comma operator without the parentheses operator to show that the comma operator is of lower precedence than the assignment (
=) operator:
var v:Number = 0;
v = 4, 5, 6;
trace(v); // 4
The following example uses the comma operator with parentheses and illustrates that the comma operator returns the value of the last expression:
var v:Number = 0;
v = (4, 5, 6);
trace(v); // 6
The following example uses the comma operator without parentheses and illustrates that the comma operator causes all of the expressions to be evaluated sequentially. The first expression,
v + 4, is assigned to the variable
v because the assignment (=) operator is of higher precedence than the comma operator. The second expression,
z++, is evaluated and
z is incremented by one.
var v:Number = 0;
var z:Number = 0;
v = v + 4 , z++, v + 6;
trace(v); // 4
trace(z); // 1
The following example is identical to the previous example except for the addition of parentheses, which changes the order of operations such that the comma operator is evaluated before the assignment (
=) operator:
var v:Number = 0;
var z:Number = 0;
v = (v + 4, z++, v + 6);
trace(v); // 6
trace(z); // 1
See also
Usage
| expression1 + expression2 |
Concatenates (combines) strings. If one expression is a string, all other expressions are converted to strings and concatenated.
If both expressions are numbers, this operator behaves as an addition operator.
Operands
| expression1:String —
A string to be concatenated.
|
| expression2:String —
A string to be concatenated.
|
Result
| String — The concatenated string. |
Example
How to use examples
The following example concatenates two strings.
var lastName:String = "Cola";
var instrument:String = "Drums";
trace(lastName + " plays " + instrument); // Cola plays Drums
This example shows that if one expression is a string, all other expressions are converted to strings and concatenated:
trace("Number " + 8 + 0); // Number 80
The following example shows how numeric sums to the right of a string expression are not calculated because they are converted to strings:
var a:String = 3 + 10 + "asdf";
trace(a); // 13asdf
var b:String = "asdf" + 3 + 10;
trace(b); // asdf310
See also
Usage
| expression1 + expression2 |
Concatenates (combines) XML or XMLList values into an XMLList object.
An XMLList object results only if both operands are XML or XMLList values.
Operands
| expression1:* —
An XML or XMLList value.
|
| expression2:* —
An XML or XMLList value.
|
Result
| XMLList — The concatenated XMLList object. |
Example
How to use examples
The following example shows how to use the XMLList (
+) (concatenation) operator:
var x1:XML =
<employee id = "42">
<firstName>Joe</firstName>
<lastName>Smith</lastName>
</employee>;
var x2:XML =
<employee id = "43">
<firstName>Susan</firstName>
<lastName>Jones</lastName>
</employee>;
var myXMLList:XMLList = x1 + x2;
trace(myXMLList.toXMLString());
The trace statement produces the following output:
<employee id = "42">
<firstName>Joe</firstName>
<lastName>Smith</lastName>
</employee>
<employee id = "43">
<firstName>Susan</firstName>
<lastName>Jones</lastName>
</employee>
See also
Usage
| expression1 += expression2 |
Assigns expression1 the value of expression1 + expression2. For example, the following two statements have the same result:
x += y;
x = x + y;
All the rules of the concatenation (
+) operator apply to the concatenation assignment (
+=) operator. Note that using concatenation assignment for the
text property of a
TextField (i.e.
someTextField.text += moreText is much less efficient than
TextField.appendText(), particularly with a
TextField that contains a significant amount of content.
Operands
| expression1:String —
A string.
|
| expression2:String —
A string.
|
Result
| Number — The result of the concatenation. |
Example
How to use examples
This example uses the
+= operator with a string expression:
var x1:String = "My name is ";
x1 += "Gilbert";
trace(x1); // My name is Gilbert
See also
Usage
| expression1 += expression2 |
Assigns expression1, which is an XMLList object, the value of expression1 + expression2.
For example, the following two statements have the same result:
x += y;
x = x + y;
All the rules of the XMLList concatenation (
+) operator apply to the XMLList concatenation assignment (
+=) operator.
Operands
| expression1:XMLList —
The XMLList object to which you are adding a new value.
|
| expression2:* —
An XML or XMLList value.
|
Example
How to use examples
The following example shows how to use the XMLList concatenation assignment (
+=) operator:
var x1:XML = <location>Athens</location>;
var x2:XML = <location>Paris</location>;
myXMLList = x1 + x2;
var x3:XML = <location>Springfield</location>;
myXMLList += x3;
trace(myXMLList.toXMLString());
The trace statement produces the following output:
<location>Athens</location>
<location>Paris</location>
<location>Springfield</location>
See also
Usage
| expression1 ? expression2 : expression3 |
Evaluates expression1, and if the value of expression1 is true, the result is the value of expression2; otherwise the result is the value of expression3.
Operands
| expression1:Boolean —
An expression that evaluates to a Boolean value; usually a comparison expression, such as x < 5.
|
| expression2:* —
A value of any type.
|
| expression3:* —
A value of any type.
|
Result
| * — The value of expression2 or expression3. |
Example
How to use examples
The following statement assigns the value of variable
x to variable
z because the first expression evaluates to
true:
var x:Number = 5;
var y:Number = 10;
var z = (x < 6) ? x: y;
trace(z); // returns 5
The following example shows a conditional statement written in shorthand:
var timecode:String = (new Date().getHours() < 11) ? "AM" : "PM";
trace(timecode);
The same conditional statement could also be written in longhand, as shown in the following example:
if (new Date().getHours() < 11) {
var timecode:String = "AM";
} else {
var timecode:String = "PM";
}
trace(timecode);
See also
Usage
| --expression expression-- |
Subtracts 1 from the operand. The operand can be a variable, element in an array, or property of an object.
The pre-decrement form of the operator (--expression) subtracts 1 from expression and returns the result.
The post-decrement form of the operator (expression--) subtracts 1 from expression and returns the initial value of expression (the value prior to the subtraction).
Operands
| expression:Number —
A number or a variable that evaluates to a number.
|
Result
| Number — The result of the decremented value. |
Example
How to use examples
The pre-decrement form of the operator decrements
x to 2 (
x -
1 = 2) and returns the result as
y:
var x:Number = 3;
var y:Number = --x; // y is equal to 2
The post-decrement form of the operator decrements
x to 2 (
x -
1 = 2) and returns the original value of
x as the result
y:
var x:Number = 3;
var y:Number = x--; // y is equal to 3
The following example loops from 10 to 1, and each iteration of the loop decreases the counter variable
i by 1:
for (var i = 10; i > 0; i--) {
trace(i);
}
See also
Usage
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Destroys the object property specified by reference; the result is true if the property does not exist after the operation completes, and false otherwise.
The delete operator returns true if it is called on a nonexistent property or a dynamic property not defined in a class.
The delete operator can fail and return false if the reference parameter cannot be deleted.
You cannot delete fixed properties or variables that are declared with the var statement.
A fixed property is a variable or method defined in a class definition.
The delete operator cannot be used to destroy a property of a class, unless that class is a dynamic class added at runtime. Properties of sealed classes cannot be destroyed using delete. Set the property to null instead.
Note: You cannot delete an object, but you can make an object eligible for garbage collection by removing all references to the object.
The most common reference to an object is a variable that points to it. You can remove such a reference by setting the variable to null.
The garbage collector removes any object that has no references.
Operands
| reference:* —
The name of the property to eliminate.
|
Result
| Boolean — The value true if the deletion succeeded and false if it failed. |
Example
How to use examples
The following example deletes a property of an object:
// create the new object "account"
var account:Object = new Object();
// assign property name to the account
account.name = "Jon";
// delete the property
delete account.name;
trace(account.name); // undefined
// delete a nonexistent property
var fooDeleted:Boolean = delete account.foo;
trace(fooDeleted); // true
The following example deletes the value of an array element, but the value of the length property is not changed:
var my_array:Array = new Array();
my_array[0] = "abc"; // my_array.length == 1
my_array[1] = "def"; // my_array.length == 2
my_array[2] = "ghi"; // my_array.length == 3
// my_array[2] is deleted, but Array.length is not changed
delete my_array[2];
trace(my_array.length); // 3
trace(my_array); // abc,def,
The following example shows how the returned Boolean from delete can be used as a condition for future code execution. Note that if an item has already been deleted, calling delete on the item again will return false.
var my_array:Array = [ "abc", "def", "ghi" ];
var deleteWasSuccessful:Boolean
deleteWasSuccessful = delete my_array[0];
if(deleteWasSuccessful) delete my_array[1];
deleteWasSuccessful = delete my_array[0];
if(deleteWasSuccessful) delete my_array[2];
trace(my_array) // outputs: undefined,undefined,ghi
See also
Usage
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Deletes the XML elements or attributes specified by reference.
When used with an XMLList operand, the result of the delete operator is always true because the XMLList operand always refers to a valid (though possibly empty) XMLList object.
Operands
| reference:XMLList —
An XMLList object that specifies the XML elements or attributes to delete.
|
Result
| Boolean — A value of true if the deletion succeeded, false if it failed. |
Example
How to use examples
The following example shows how to delete an attribute, then
delete a single element, then delete multiple elements:
var x1:XML = <x1>
<a id = "52">AYY</a>
<a>AYY 2 </a>
<b>BEE</b>
<c>CEE</c>
</x1>;
trace(x1.toXMLString());
trace("___________");
delete x1.a.@id;
trace(x1.toXMLString());
trace("___________");
delete x1.b;
trace(x1.toXMLString());
trace("___________");
delete x1.a;
trace(x1.toXMLString());
The output is as follows:
<x1>
<a id="52">AYY</a>
<a>AYY 2</a>
<b>BEE</b>
<c>CEE</c>
</x1>
___________
<x1>
<a>AYY</a>
<a>AYY 2</a>
<b>BEE</b>
<c>CEE</c>
</x1>
___________
<x1>
<a>AYY</a>
<a>AYY 2</a>
<c>CEE</c>
</x1>
___________
<x1>
<c>CEE</c>
</x1>
The following example shows how to delete all contents of an element, including attributes
and child elements, without deleting the element itself:
var xml:XML =
<order>
<item id="121">hamburger</item>
<item id="122">fries</item>
<item id="123">chocolate shake</item>
</order>;
delete xml.item[1].*;
delete xml.item[1].@*;
trace(xml);
The output for this example is the following:
<order>
<tem id="121">hamburger</item>
<item/>
<item id="123">chocolate shake</item>
</order>
Usage
| myXML..childElement1..@attributeName |
Navigates to descendant elements of an XML or XMLList object,
or (combined with the @ operator) finds matching attributes of descendants.
The matching elements or attributes need not be direct children of the XML or XMLList object;
they can be lower in the tree (for example, grandchildren). The result is an XMLList object,
because more than one child element or attribute can match.
The order of nodes in the XMLList object returned is the result of a depth-first traversal. For example, consider the following:
var myXML:XML = <a>
<b>one
<c>
<b>two</b>
</c>
</b>
<b>three</b>
</a>;
trace(myXML..b[0].toXMLString());
trace("______________");
trace(myXML..b[1].toXMLString());
trace("______________");
trace(myXML..b[2].toXMLString());
The following output would result:
<b>
one
<c>
<b>two</b>
</c>
</b>
______________
<b>two</b>
______________
<b>three</b>
To return descendants with names that match ActionScript reserved words, use the
XML.descendants() method instead of the descendant (..) operator, as the
following example shows:
var xml:XML =
<enrollees>
<student id="239">
<class name="Algebra" />
<class name="Spanish 2"/>
</student>
<student id="206">
<class name="Trigonometry" />
<class name="Spanish 2" />
</student>
</enrollees>;
trace(xml.descendants("class"));
Operands
| myXML:Object —
The XML or XMLList object.
|
| childElement1_or_attributeName —
The name of an XML property or the name of an attribute.
|
Example
How to use examples
The following example shows how to use the descendant accessor (..) operator to return descendant elements of an XML object and to return an attribute of an element:
var myXML:XML =
<employees>
<employee id = "42">
<firstName>Billy</firstName>
<lastName>Einstein</lastName>
</employee>
<employee id = "43">
<firstName>Sally</firstName>
<lastName>Shostakovich</lastName>
</employee>
</employees>
trace(myXML..firstName);
// <firstName>Billy</firstName>
// <firstName>Sally</firstName>
trace(myXML..@id); //4243
See also
Usage
| expression1 / expression2 |
Divides expression1 by expression2. The result of the division operation is a double-precision floating-point number.
Operands
| expression:Number —
A number or a variable that evaluates to a number.
|
Result<