Symbolic operators are characters that specify how to combine, compare, or modify the values of an expression.
Arithmetic | |||
---|---|---|---|
+ | addition | ||
-- | decrement | ||
/ | division | expression1 by expression2 . | |
++ | increment | ||
% | modulo | expression1 divided by expression2 . | |
* | multiplication | ||
- | subtraction | ||
Arithmetic compound assignment | |||
+= | addition assignment | expression1 the value of expression1 + expression2 . | |
/= | division assignment | expression1 the value of expression1 / expression2 . | |
%= | modulo assignment | expression1 the value of expression1 % expression2 . | |
*= | multiplication assignment | expression1 the value of expression1 * expression2 . | |
-= | subtraction assignment | expression1 the value of expression1 - expression2 . | |
Assignment | |||
= | assignment | expression2 (the operand on the right) to the variable, array element, or property in expression1 . | |
Bitwise | |||
& | bitwise AND | expression1 and expression2 to 32-bit unsigned integers, and performs a Boolean AND operation on each bit of the integer parameters. | |
<< | bitwise left shift | 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 | expression to a 32-bit signed integer, and then applies a bitwise one's complement. | |
| | bitwise OR | 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 | 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 | >> ) 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 | 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 | expression1 the value of expression1 & expression2 . | |
<<= | bitwise left shift and assignment | <<= ) operation and stores the contents as a result in expression1 . | |
|= | bitwise OR assignment | expression1 the value of expression1 | expression2 . | |
>>= | bitwise right shift and assignment | expression . | |
>>>= | bitwise unsigned right shift and assignment | expression . | |
^= | bitwise XOR assignment | expression1 the value of expression1 ^ expression2 . | |
Comment | |||
/*..*/ | block comment delimiter | ||
// | line comment delimiter | ||
Comparison | |||
== | equality | ||
> | greater than | expression1 is greater than expression2 ; if it is, the result is true . | |
>= | greater than or equal to | expression1 is greater than or equal to expression2 (true ) or expression1 is less than expression2 (false ). | |
!= | inequality | == ) operator. | |
< | less than | expression1 is less than expression2 ; if so, the result is true . | |
<= | less than or equal to | expression1 is less than or equal to expression2 ; if it is, the result is true . | |
=== | strict equality | ||
!== | strict inequality | === ) operator. | |
Logical | |||
&& | logical AND | expression1 if it is false or can be converted to false , and expression2 otherwise. | |
&&= | logical AND assignment | expression1 the value of expression1 && expression2 . | |
! | logical NOT | ||
|| | logical OR | expression1 if it is true or can be converted to true , and expression2 otherwise. | |
||= | logical OR assignment | expression1 the value of expression1 || expression2 . | |
Other | |||
[] | array access | a0 , and so on), or accesses elements in an array. | |
as | |||
, | comma | expression1 , then expression2 , and so on. | |
?: | conditional | 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 | reference ; the result is true if the property does not exist after the operation completes, and false otherwise. | ||
. | dot | ||
in | |||
instanceof | function . | ||
is | |||
:: | name qualifier | ||
new | |||
{} | object initializer | name and value property pairs. | |
() | parentheses | ||
/ | RegExp delimiter | ||
: | type | ||
typeof | expression and returns a string specifying the expression's data type. | ||
void | undefined . | ||
String | |||
+ | concatenation | ||
+= | concatenation assignment | expression1 the value of expression1 + expression2 . | |
" | string delimiter | ||
XML | |||
@ | attribute identifier | ||
{ } | braces (XML) | ||
[ ] | brackets (XML) | ||
+ | concatenation (XMLList) | ||
+= | concatenation assignment (XMLList) | expression1 , which is an XMLList object, the value of expression1 + expression2 . | |
delete (XML) | reference . | ||
.. | descendant accessor | ||
. | dot (XML) | ||
( ) | parentheses (XML) | ||
< > | XML literal tag delimiter |
+ addition | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:Number —
A value to be added.
| |
expression2:Number —
A value to be added.
|
Number —
An integer or floating-point number.
|
Example
How to use this example
This statement adds the integers 2 and 3:
trace(2 + 3); // 5
trace(2.5 + 3.25); // 5.75
trace("Number " + 8 + 0); // Number 80
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);
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);
Related API Elements
+= addition assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:Number —
A number.
| |
expression2:Number —
A number.
|
Number —
The result of the addition.
|
Example
How to use this example
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
Related API Elements
[] array access | Operator |
|
Runtime Versions: | 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"];
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.*/
var my_array:Array = new Array(); my_array[0] = 15; my_array[1] = "Hello"; my_array[2] = true;
my_array[3] = "George";
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
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 */
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.
|
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 this example
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
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 */
Related API Elements
as | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression:* —
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.
|
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 this example
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
Related API Elements
= assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:* —
A variable, element of an array, or property of an object.
| |
expression2:* —
A value of any type.
|
Object —
The assigned value, expression2 .
|
Example
How to use this example
The following example uses assignment by value to assign the value of 5 to the variable
z
.
var z:Number = 5;
hello
" to the variable z
:
var x:String; x = "hello";
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";
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
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
Related API Elements
@ attribute identifier | Operator |
myXML.@attributeName |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
attributeName:* —
The name of the attribute.
|
Example
How to use this example
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
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 }
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"));
Related API Elements
& bitwise AND | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:Number —
A number or expression that evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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)
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
Related API Elements
&= bitwise AND assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
|
int —
The value of expression1 & expression2 .
|
Example
How to use this example
The following example assigns the value 9 to
x
:
var x:Number = 15; var y:Number = 9; trace(x &= y); // 9
Related API Elements
<< bitwise left shift | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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
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.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
In the following example, the integer 1 is shifted 10 bits to the left:
x = 1 << 10
00000000001 binary << 10 decimal -------------- 10000000000 binary equals 1024 decimal
In the following example, the integer 7 is shifted 8 bits to the left:
x = 7 << 8
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
Related API Elements
<<= bitwise left shift and assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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
Related API Elements
~ bitwise NOT | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression:Number —
A number to be converted.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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
Related API Elements
| bitwise OR | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:Number —
A number.
| |
expression2:Number —
A number.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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)
|
(bitwise OR) with ||
(logical OR).
Related API Elements
|= bitwise OR assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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)
Related API Elements
>> bitwise right shift | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression:Number —
A number or expression to be shifted right.
| |
shiftCount:Number —
A number or expression that converts to an integer from 0 to 31.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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
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
11111111111111111111111111111000 binary (-8 decimal) >> 1 decimal -------------------- 11111111111111111111111111111100 binary (-4 decimal)
Related API Elements
>>= bitwise right shift and assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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.
Related API Elements
>>> bitwise unsigned right shift | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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)
.
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.
|
uint —
The result of the bitwise operation.
|
Example
How to use this example
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
Related API Elements
>>>= bitwise unsigned right shift and assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
|
uint —
The result of the bitwise operation.
|
Example
How to use this example
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
Related API Elements
^ bitwise XOR | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:Number —
A number or expression that evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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)
Related API Elements
^= bitwise XOR assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Assigns expression1
the value of expression1 ^ expression2
. For example, the following two statements are equivalent:
x ^= y x = x ^ yOperands
expression1:Number —
A number or expression that evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number.
|
int —
The result of the bitwise operation.
|
Example
How to use this example
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)
Related API Elements
/*..*/ block comment delimiter | Operator |
/* comment */ /* comment comment */ |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
comment:* —
Any characters.
|
Example
How to use this example
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;
/* 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 */
Related API Elements
{ } braces (XML) | Operator |
myXML = <{tagName} {attributeName} = {attributeValue}>{content}{tagName}> |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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
.
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 this example
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>
Related API Elements
[ ] brackets (XML) | Operator |
myXML[expression] |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
myXML:* —
An XML or XMLList object.
| |
expression:* —
An expression that evaluates to the name of an XML tag or attribute.
|
Example
How to use this example
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"]);
Related API Elements
, comma | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
expression1:* —
An expression to be evaluated.
| |
expression2:* —
An expression to be evaluated.
| |
expressionN:* —
Any number of additional expressions to be evaluated.
|
Object —
The values of the evaluated expressions.
|
Example
How to use this example
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
=
) operator:
var v:Number = 0; v = 4, 5, 6; trace(v); // 4
var v:Number = 0; v = (4, 5, 6); trace(v); // 6
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
=
) operator:
var v:Number = 0; var z:Number = 0; v = (v + 4, z++, v + 6); trace(v); // 6 trace(z); // 1
Related API Elements
+ concatenation | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:String —
A string to be concatenated.
| |
expression2:String —
A string to be concatenated.
|
String —
The concatenated string.
|
Example
How to use this example
The following example concatenates two strings.
var lastName:String = "Cola"; var instrument:String = "Drums"; trace(lastName + " plays " + instrument); // Cola plays Drums
trace("Number " + 8 + 0); // Number 80
var a:String = 3 + 10 + "asdf"; trace(a); // 13asdf var b:String = "asdf" + 3 + 10; trace(b); // asdf310
Related API Elements
+ concatenation (XMLList) | Operator |
expression1 + expression2 |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Concatenates (combines) XML or XMLList values into an XMLList object. An XMLList object results only if both operands are XML or XMLList values.
Operandsexpression1:* —
An XML or XMLList value.
| |
expression2:* —
An XML or XMLList value.
|
XMLList —
The concatenated XMLList object.
|
Example
How to use this example
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>
Related API Elements
+= concatenation assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:String —
A string.
| |
expression2:String —
A string.
|
Number —
The result of the concatenation.
|
Example
How to use this example
This example uses the
+=
operator with a string expression:
var x1:String = "My name is "; x1 += "Gilbert"; trace(x1); // My name is Gilbert
Related API Elements
+= concatenation assignment (XMLList) | Operator |
expression1 += expression2 |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandsexpression1:XMLList —
The XMLList object to which you are adding a new value.
| |
expression2:* —
An XML or XMLList value.
|
Example
How to use this example
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>
Related API Elements
?: conditional | Operator |
expression1 ? expression2 : expression3 |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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
.
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.
|
* —
The value of expression2 or expression3 .
|
Example
How to use this example
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
var timecode:String = (new Date().getHours() < 11) ? "AM" : "PM"; trace(timecode);
if (new Date().getHours() < 11) { var timecode:String = "AM"; } else { var timecode:String = "PM"; } trace(timecode);
-- decrement | Operator |
--expression expression-- |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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).
expression:Number —
A number or a variable that evaluates to a number.
|
Number —
The result of the decremented value.
|
Example
How to use this example
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
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
i
by 1:
for (var i = 10; i > 0; i--) { trace(i); }
delete | Operator |
delete reference |
Language Version: | ActionScript 3.0 |
Runtime Versions: | 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.
reference:* —
The name of the property to eliminate.
|
Boolean —
The value true if the deletion succeeded and false if it failed.
|
Example
How to use this example
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
Related API Elements
delete (XML) | Operator |
delete reference |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Deletes the XML elements or attributes specified by reference
.
reference:XMLList —
An XMLList object that specifies the XML elements or attributes to delete.
|
Boolean —
Always returns a value of true . The result is always true because the XMLList operand always refers to a valid (though possibly empty) XMLList object.
|
Example
How to use this example
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>
.. descendant accessor | Operator |
myXML..childElement1..@attributeName |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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"));
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 this example
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
Related API Elements
/ division | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Divides expression1
by expression2
. The result of the division operation is a double-precision floating-point number.
expression:Number —
A number or a variable that evaluates to a number.
|
Number —
The floating-point result of the operation.
|
Example
How to use this example
The following example shows that the results of dividing by 0 differs if the dividend is positive, negative or 0.
trace(3/0); // Infinity trace(-3/0); // -Infinity trace(0/0); // NaN
Related API Elements
/= division assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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 a variable that evaluates to a number.
| |
expression2:Number —
A number or a variable that evaluates to a number.
|
Number —
A number.
|
Example
How to use this example
The following code shows the division assignment (
/=
) operator used with variables and numbers:
var a:Number = 10; var b:Number = 2; a /= b; trace(a); // 5
Related API Elements
. dot | Operator |
object.property_or_method |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Accesses class variables and methods, gets and sets object properties, and delimits imported packages or classes.
Operandsobject:Object —
An instance of a class. The object can be an instance of any of the built-in ActionScript classes or a class you define. This operand is always to the left of the dot (.) operator.
| |
property_or_method:* —
The name of a property or method associated with an object. All the valid methods and properties for the built-in classes are listed in the method and property summary tables for that class. This operand is always to the right of the dot (.) operator.
|
* —
The variable, method, or property named on the right side of the dot.
|
Example
How to use this example
The following example uses the dot operator as a delimiter when importing the Timer class.
import flash.utils.Timer;
var obj:Object = new Object(); obj.propertyA = "hello"; trace(obj.propertyA); // hello
Related API Elements
. dot (XML) | Operator |
myXML.childElement myXML.@attributeName |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Navigates to child elements of an XML or XMLList object, or (combined with the @ operator) returns attributes of an XML or XMLList object. The object returned is an XMLList, because more than one child element or attribute can match.
To return elements with names that match
ActionScript reserved words, use the XML.elements()
method or the XML.descendants()
method instead of the
XML dot (.) operator, as the following example shows:
var xml:XML = <student id="206"> <class name="Trigonometry" /> <class name="Spanish 2" /> </student>; trace(xml.elements("class")); trace(xml.descendants("class"));
myXML:Object —
The XML or XMLList object.
| |
childElement:* —
The name of an XML property.
| |
attributeName:* —
The name of an attribute.
|
XMLList —
The XMLList specified.
|
Example
How to use this example
The following example shows how to use the dot (.) operator to return to a child element of an XML object and to return an attribute of an element:
var myXML:XML = <employee id = "42"> <firstName>Billy</firstName> <lastName>Einstein</lastName> </employee>; trace(myXML.firstName); // Billy trace(myXML.@id); // 42
Related API Elements
== equality | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Tests two expressions for equality. The result is true
if the expressions are equal.
If the data types of the two operands match, the definition of equal depends on the data type of the operands:
- Values of type int, uint, and Boolean are considered equal if they have the same value.
- Numbers with matching values are considered equal, unless they are both
NaN
. - If the value of both operands is
null
orundefined
, they are considered equal. - String expressions are equal if they have the same number of characters and the characters are identical.
- For XML objects:
- If one operand is a text or attribute node and the other has simple content, both operands are converted to strings with the
toString()
method and are considered equal if the resulting strings match. - Otherwise, objects are considered equal only if the qualified name, attributes, and child properties for both objects match.
- If one operand is a text or attribute node and the other has simple content, both operands are converted to strings with the
- XMLList objects are considered equal if they have the same number of properties and both the order and values of the properties match.
- For Namespace objects, values are considered equal if the
uri
properties of both objects match. - For QName objects, values are considered equal if the
uri
properties of both objects match and thelocalName
properties of both objects match. - Variables representing objects, arrays, and functions are compared by reference. Two such variables are equal if they refer to the same object, array, or function. Two separate arrays are never considered equal, even if they have the same number of elements.
false
except in the following circumstances:
- The operands' values are
undefined
andnull
, in which case the result istrue
. - Automatic data type conversion converts the data types of String, Boolean, int, uint, and Number values to compatible types and the converted values are equal, in which case operands are considered equal.
- One operand is of type XML with simple content (
hasSimpleContent() == true
), and after both operands are converted to strings with thetoString()
method, the resulting strings match. - One operand is of type XMLList, and either of the following conditions is true:
- The
length
property of the XMLList object is 0, and the other object isundefined
. - The
length
property of the XMLList object is 1, and one element of the XMLList object matches the other operand.
- The
expression1:Object —
A number, string, Boolean value, variable, object, array, or expression.
| |
expression2:Object —
A number, string, Boolean value, variable, object, array, or expression.
|
Boolean —
A value of true if the expressions are equal, and false otherwise.
|
Example
How to use this example
The following example uses the equality (
==
) operator with an if
statement:
var a:String = "David" var b:String = "David"; if (a == b) { trace("David is David"); }
var a:Number = 5; var b:String = "5"; trace(a == b); // true
true
is converted to 1 and false
is converted to 0:
var c:Number = 1; var d:Boolean = true; trace(c == d); // true var e:Number = 0; var f:Boolean = false; trace(e == f); // true
false
:
var g:String = "true"; var h:Boolean = true; trace(g == h); // false
false
for these two arrays.
Although the arrays appear equal, comparison by reference requires that both firstArray
and secondArray
refer to the same array.
The second example creates the thirdArray
variable, which points to the same array as firstArray
.
The equality operator returns true for these two arrays because the two variables refer to the same array.
var firstArray:Array = new Array("one", "two", "three"); var secondArray:Array = new Array("one", "two", "three"); trace(firstArray == secondArray); // false /* Arrays are only considered equal if the variables refer to the same array. */ var thirdArray:Array = firstArray; trace(firstArray == thirdArray); // true
Related API Elements
> greater than | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Compares two expressions and determines whether expression1
is greater than expression2
; if it is, the result is true
.
If expression1
is less than or equal to expression2
, the result is false
.
If both operands are of type String, the operands are compared using alphabetical order; all capital letters come before lowercase letters. Otherwise, operands are first converted to numbers, then compared.
Operandsexpression1:Object —
A string, integer, or floating-point number.
| |
expression2:Object —
A string, integer, or floating-point number.
|
Boolean —
A value of true if expression1 is greater than expression2 ; false otherwise.
|
Example
How to use this example
The following example shows that strings are compared alphabetically, with capital letters before lowercase letters:
var a:String = "first"; var b:String = "First"; trace(a > b); // true
var c:Number = 5; var d:String = "4"; trace(c > d); // true var e: Number = 2; var f:Boolean = true; trace(e > f); // true
>= greater than or equal to | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Compares two expressions and determines whether expression1
is greater than or equal to expression2
(true
) or expression1
is less than expression2
(false
).
expression1:Object —
A string, integer, or floating-point number.
| |
expression2:Object —
A string, integer, or floating-point number.
|
Boolean —
A value of true if expression1 is greater than or equal to expression2 ; false otherwise.
|
Example
How to use this example
In the following example, the greater than or equal to (>=) operator is used to determine whether the current hour is greater than or equal to 12:
if (new Date().getHours() >= 12) { trace("good afternoon"); } else { trace("good morning"); }
Related API Elements
in | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Evaluates whether a property is part of a specific object.
To use the in
operator, specify a property name as the first operand
and an object as the second operand. If the object you specify contains such a
property, the result is true
; otherwise the result is false
.
If the specified object is an Array object, you can use the in
operator to check whether a particular index number is valid. If you pass an
integer as the first operand, the result is true
if the index is
within the valid range of index numbers, and false
otherwise.
Boolean —
A value of true if expression1 is a property of the object represented by expression2 , and false otherwise.
|
Example
How to use this example
The following example uses the
in
operator to show that PI
is a property of the Math object, but that myProperty
is not.
trace("PI" in Math); // true trace("myProperty" in Math); // false
The following example uses the in
operator to show that the numbers 0, 1, and 2 are valid index numbers in the myArray
object, but that the number 3 is not.
public var myArray:Array = ["zero", "one", "two"]; trace(0 in myArray); // true trace(1 in myArray); // true trace(2 in myArray); // true trace(3 in myArray); // false
Related API Elements
++ increment | Operator |
++expression expression++ |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Adds 1 to an expression.
The expression can be a variable, an element in an array, or a property of an
object. The pre-increment form of the operator (++expression
) adds 1 to
expression
and returns the result. The post-increment form of the operator
(expression++
) adds 1 to expression
and returns the
initial value of expression
(the value prior to the addition).
expression:Number —
A number or a variable that evaluates to a number.
|
Number —
The result of the increment.
|
Example
How to use this example
The following example uses ++ as a pre-increment operator in a
while
loop to
show that the value added to the array is the value that has been incremented:
var preInc:Array = new Array(); var i:int = 0; while (i < 10) { preInc.push(++i); } trace(preInc); // 1,2,3,4,5,6,7,8,9,10
while
loop to
show that the value added to the array is the initial value:
var postInc:Array = new Array(); var i:int = 0; while (i < 10) { postInc.push(i++); } trace(postInc); // 0,1,2,3,4,5,6,7,8,9
while
loop run five times:
var i:int = 0; while (i++ < 5) { trace("this is execution " + i); } /* output: this is execution 1 this is execution 2 this is execution 3 this is execution 4 this is execution 5 */
!= inequality | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Tests for the exact opposite of the equality (==
) operator. If expression1
is equal to expression2
, the result is false
. As with the equality (==
) operator, the definition of equal depends on the data types being compared.
If the data types of the two operands match, the definition of equal depends on the data type of the operands:
- Values of type int, uint, and Boolean are considered equal if they have the same value.
- Numbers with matching values are considered equal, unless they are both
NaN
. - If the value of both operands is
null
orundefined
, they are considered equal. - String expressions are equal if they have the same number of characters and the characters are identical.
- For XML objects:
- If one operand is a text or attribute node and the other has simple content, both operands are converted to strings with the
toString()
method and are considered equal if the resulting strings match. - Otherwise, objects are considered equal only if the qualified name, attributes, and child properties for both objects match.
- If one operand is a text or attribute node and the other has simple content, both operands are converted to strings with the
- XMLList objects are considered equal if they have the same number of properties and both the order and values of the properties match.
- For Namespace objects, values are considered equal if the
uri
properties of both objects match. - For QName objects, values are considered equal if the
uri
properties of both objects match and thelocalName
properties of both objects match. - Variables representing objects, arrays, and functions are compared by reference. Two such variables are equal if they refer to the same object, array, or function. Two separate arrays are never considered equal, even if they have the same number of elements.
!=
) returns true
except in the following circumstances:
- The operands' values are
undefined
andnull
, in which case the result istrue
. - Automatic data type conversion converts the data types of String, Boolean, int, uint, and Number values to compatible types and the converted values are equal, in which case operands are considered equal.
- One operand is of type XML with simple content (
hasSimpleContent() == true
), and after both operands are converted to strings with thetoString()
method the resulting strings match. - One operand is of type XMLList, and either of the following conditions is true:
- The
length
property of the XMLList object is 0, and the other object isundefined
. - The
length
property of the XMLList object is 1, and one element of the XMLList object matches the other operand.
- The
expression1:Object —
A number, string, Boolean value, variable, object, array, or function.
| |
expression2:Object —
A number, string, Boolean value, variable, object, array, or function.
|
Boolean —
A value of true if the expressions are not equal, and false otherwise.
|
Example
How to use this example
The following example illustrates the result of the inequality (
!=
) operator:
trace(5 != 8); // true trace(5 != 5); // false
!=
) operator in an if
statement:
var a:String = "David"; var b:String = "Fool"; if (a != b) { trace("David is not a fool"); }
var a:Function = function() { trace("foo"); }; var b:Function = function() { trace("foo"); }; a(); // foo b(); // foo trace(a != b); // true a = b; a(); // foo b(); // foo trace(a != b); // false
var a:Array = [ 1, 2, 3 ]; var b:Array = [ 1, 2, 3 ]; trace(a); // 1,2,3 trace(b); // 1,2,3 trace(a != b); // true a = b; trace(a); // 1,2,3 trace(b); // 1,2,3 trace(a != b); // false
Related API Elements
instanceof | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Evaluates whether an expression's prototype chain includes the prototype object for function
.
The instanceof
operator is included for backward compatibility with ECMAScript edition 3,
and may be useful for advanced programmers who choose to use prototype-based inheritance with constructor functions instead of classes.
To check whether an object is a member of a specific data type, use the is
operator.
When used with classes, the instanceof
operator is similar to the is
operator because a class's prototype chain includes all of its superclasses.
Interfaces, however, are not included on prototype chains, so the instanceof
operator always results in false
when used with interfaces,
whereas the is
operator results in true
if an object belongs to a class that implements the specified interface.
Note: The ActionScript is
operator is the equivalent of the Java instanceof
operator.
expression:Object —
The object that contains the prototype chain to evaluate.
| |
function:Object —
A function object (or class).
|
Boolean —
Returns true if the prototype chain of expression includes the prototype object for function , and false otherwise.
|
Example
How to use this example
The following example creates an instance of the Sprite class named
mySprite
and uses the instanceof
operator to test whether
the prototype chain of mySprite
includes the prototype objects of the Sprite and DisplayObject classes.
The result is true
with the Sprite class and the DisplayObject class because the prototype objects for Sprite and DisplayObject are on the prototype chain of mySprite
.
var mySprite:Sprite = new Sprite(); trace(mySprite instanceof Sprite); // true trace(mySprite instanceof DisplayObject); // true
instanceof
operator does not work with interfaces.
The is
operator results in true
because the DisplayObject class, which is a superclass of the Sprite class, implements the IBitmapDrawable interface.
var mySprite:Sprite = new Sprite(); trace(mySprite instanceof IBitmapDrawable); // false trace(mySprite is IBitmapDrawable); // true
Related API Elements
is | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Evaluates whether an object is compatible with a specific data type, class, or interface.
Use the is
operator instead of the instanceof
operator for type comparisons.
You can also use the is
operator to check whether an object implements an interface.
Boolean —
A value of true if expression1 is compatible with the data type, class, or interface specified in expression2 , and false otherwise.
|
Example
How to use this example
The following example creates an instance of the Sprite class named
mySprite
and uses the is
operator to test whether mySprite
is an instance of the Sprite and DisplayObject classes, and whether it implements the IEventDispatcher interface.
import flash.display.*; import flash.events.IEventDispatcher; var mySprite:Sprite = new Sprite(); trace(mySprite is Sprite); // true trace(mySprite is DisplayObject); // true trace(mySprite is IEventDispatcher); // true
Related API Elements
< less than | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Compares two expressions and determines whether expression1
is less than expression2
; if so, the result is true
.
If expression1
is greater than or equal to expression2
, the result is false
.
If both operands are of type String, the operands are compared using alphabetical order; all capital letters come before lowercase letters. Otherwise, operands are first converted to numbers, then compared.
Operandsexpression1:Object —
A string, integer, or floating-point number.
| |
expression2:Object —
A string, integer, or floating-point number.
|
Boolean —
A value of true if expression1 is less than expression2 ; false otherwise.
|
Example
How to use this example
The following examples show
true
and false
results for both numeric and string comparisons:
trace(5 < 10); // true trace(2 < 2); // false trace(10 < 3); // false trace("Allen" < "Jack"); // true trace("Jack" < "Allen"); // false trace("11" < "3"); // true trace("11" < 3); // false (numeric comparison) trace("C" < "abc"); // true trace("A" < "a"); // true
<= less than or equal to | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Compares two expressions and determines whether expression1
is less than or equal to expression2
;
if it is, the result is true
. If expression1
is greater than expression2
, the result is false
.
If both operands are of type String, the operands are compared using alphabetical order; all capital letters come before lowercase letters. Otherwise, operands are first converted to numbers, then compared.
Operandsexpression1:Object —
A string, integer, or floating-point number.
| |
expression2:Object —
A string, integer, or floating-point number.
|
Boolean —
A value of true if expression1 is less than or equal to expression2 ; false otherwise.
|
Example
How to use this example
The following examples show
true
and false
results for both numeric and string comparisons:
trace(5 <= 10); // true trace(2 <= 2); // true trace(10 <= 3); // false trace("Allen" <= "Jack"); // true trace("Jack" <= "Allen"); // false trace("11" <= "3"); // true trace("11" <= 3); // false (numeric comparison) trace("C" <= "abc"); // true trace("A" <= "a"); // true
// line comment delimiter | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Indicates the beginning of a script comment. Characters that appear between the comment delimiter (//
) and the end-of-line character are interpreted as a comment and are ignored.
Use this delimiter for single-line comments; for comments on multiple successive lines, use the /*
and */
delimiters.
comment:* —
Any characters.
|
Example
How to use this example
The following example shows a single-line comment:
// Any text following a line comment delimiter is ignored during compilation
Related API Elements
&& logical AND | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Returns expression1
if it is false
or can be converted to false
, and expression2
otherwise.
Examples of values that can be converted to false
are 0, NaN
, null
, and undefined
.
If you use a function call as expression2
, the function is not called if expression1
evaluates to false
.
If both operands are of type Boolean, the result is true
only if both operands are true
, as
shown in the following table:
Expression | Evaluates |
---|---|
|
|
|
|
|
|
|
|
expression1:* —
A value or expression of any type.
| |
expression2:* —
A value of expression of any type.
|
* —
A Boolean value if both operands are of type Boolean. Otherwise, the result is the value of either expression.
|
Example
How to use this example
The following example uses the logical AND (
&&
) operator to perform a test to determine if a player has won the game. The turns
variable and the score
variable are updated when a player takes a turn or scores points during the game. The script outputs "You Win the Game!" when the player's score reaches 75 or higher in three or fewer turns.
var turns:Number = 2; var score:Number = 77; if ((turns <= 3) && (score >= 75)) { trace("You Win the Game!"); } else { trace("Try Again!"); }
Related API Elements
&&= logical AND assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Assigns expression1
the value of expression1 && expression2
. For example, the following two statements are equivalent:
x &&= y; x = x && y;Operands
expression1:* —
A value of any type.
| |
expression2:* —
A value of any type.
|
* —
A Boolean value if both operands are members of the Boolean data type. Otherwise, the result will be the value of either of the two expressions.
|
Example
How to use this example
The following example changes the
myVar
variable into an XML tag, unless myVar
is null. The example modifies the myVar
variable as long as the variable does not evaluate to false
. This technique takes advantage of the fact that the logical AND (&&
) operator returns the value of expression1
if expression1
evaluates to false
and otherwise returns the value of expression2
.
If myVar
already contains a value that evaluates to true
, myVar
is modified to resemble an XML tag. However, if myVar
contains a value that evaluates to false
, such as the values null
, ""
(empty string), and undefined
, myVar
remains unchanged.
var myVar:String = 'tag'; myVar &&= "<" + myVar + "/>"; trace (myVar); // output: <tag/>
if
statement, as shown in the following example:
var myVar:String = 'tag'; if (myVar != '') { myVar = "<" + myVar + "/>"; } trace (myVar); // output: <tag/>
if
statement is that the code is easier to read, whereas the advantage of using the logical AND assignment (&&=
) operator is that it you need not specify the exact default value for a given data type.
Related API Elements
! logical NOT | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Inverts the Boolean value of a variable or expression. If expression
is a variable with the absolute or converted value true
, the value of !expression
is false
. If the expression x && y
evaluates to false
, the expression !(x && y)
evaluates to true
.
The following expressions illustrate the result of using the logical NOT (!) operator:
!true
returnsfalse
.!false
returnstrue
.
expression:Boolean —
An expression or a variable that evaluates to a Boolean value.
|
Boolean —
The Boolean result of the logical operation.
|
Example
How to use this example
In the following example, the variable
happy
is set to false
.
The if
condition evaluates the condition !happy
, and if the condition is true
,
the trace()
statement outputs a string.
var happy:Boolean = false; if (!happy) { trace("don't worry, be happy"); // don't worry, be happy }
trace
statement executes because !false
equals true
.
Related API Elements
|| logical OR | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Returns expression1
if it is true
or can be converted to true
, and expression2
otherwise.
If you use a function call as expression2
, the function is not called if expression1
evaluates to true
.
If both operands are of type Boolean, the result is true
if either or both expressions are true
; the result is false
only if both expressions are false
, as shown in the following table:
Expression | Evaluates |
---|---|
|
|
|
|
|
|
|
|
expression1:* —
A value of any type.
| |
expression2:* —
A value of any type.
|
* —
A Boolean value if both operands are members of the Boolean data type. Otherwise, the result will be the value of either of the two expressions.
|
Example
How to use this example
The following example uses the logical OR (
||
) operator in an if
statement. The second expression evaluates to true,
so the final result is true
:
var a:Number = 10; var b:Number = 250; var start:Boolean = false; if ((a > 25) || (b > 200) || (start)) { trace("the logical OR test passed"); // the logical OR test passed }
if
statement is true (b > 200
).
The following example demonstrates how using a function call as the second operand can lead to unexpected results. If the expression on the left of the operator evaluates to true
, that result is returned without evaluating the expression on the right (the function fx2()
is not called).
function fx1():Boolean { trace("fx1 called"); return true; } function fx2():Boolean { trace("fx2 called"); return true; } if (fx1() || fx2()) { trace("IF statement entered"); }
Related API Elements
||= logical OR assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Assigns expression1
the value of expression1 || expression2
. For example, the following two statements are equivalent:
x ||= y; x = x || y;Operands
expression1:* —
A value of any type.
| |
expression2:* —
A value of any type.
|
* —
A Boolean value if both operands are members of the Boolean data type. Otherwise, the result will be the value of either of the two expressions.
|
Example
How to use this example
The following example assigns a default value to a previously declared variable named
myVar
. This technique takes advantage of the fact that the logical OR (||
) operator returns the value of expression1
if expression1
evaluates to true
and otherwise returns the value of expression2
.
If myVar
already contains a value that evaluates to true
, myVar
is unchanged. However, if myVar
contains a value that evaluates to false
, such as the values null
, ""
(empty string), and undefined
among others, myVar
is assigned the value "default"
.
myVar ||= "default";
Related API Elements
% modulo | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Calculates the remainder of expression1
divided by expression2
. If either operand is non-numeric, the modulo (%
) operator attempts to convert it to a number.
The sign of the modulo result matches the sign of the dividend (the first number). For example, -4 % 3
and -4 % -3
both evaluate to -1
.
expression1:Number —
A number or expression that evaluates to a number. A string that contains only numeric characters evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number. A string that contains only numeric characters evaluates to a number.
|
Number —
The result of the arithmetic operation.
|
Example
How to use this example
The following numeric example uses the modulo (
%
) operator:
trace(12 % 5); // 2 trace(4.3 % 2.1); // 0.0999999999999996 trace(4 % 4); // 0
%
) operator returns only the remainder. The second trace returns 0.0999999999999996 instead of the expected 0.1 because of the limitations of floating-point accuracy in binary computing.
Related API Elements
%= modulo assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Assigns expression1
the value of expression1 % expression2
. 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.
|
Number —
The result of the arithmetic operation.
|
Example
How to use this example
The following example assigns the value 4 to the variable
a
:
var a:Number = 14; var b:Number = 5; a %= b; trace(a); // 4
Related API Elements
* multiplication | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Multiplies two numerical expressions. If both expressions are integers, the product is an integer. If either or both expressions are floating-point numbers, the product is a floating-point number.
Operandsexpression1:Number —
A number or expression that evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number.
|
Number —
An integer or floating-point number.
|
Example
How to use this example
The following statement multiplies the integers 2 and 3, resulting in the integer 6:
trace(2*3); // 6
trace(2.0 * 3.1416); // 6.2832
*= multiplication assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Assigns expression1
the value of expression1 * expression2
. For example, the following two expressions are equivalent:
x *= y x = x * yOperands
expression1:Number —
A number or expression that evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number.
|
Number —
The value of expression1 * expression2 . If an expression cannot be converted to a numeric value, it returns NaN (not a number).
|
Example
How to use this example
The following example assigns the value 50 to the variable
a
:
var a:Number = 5; var b:Number = 10; trace(a *= b); // 50
c
and d
:
var i:Number = 5; var c:Number = 4 - 6; var d:Number = i + 2; trace(c *= d); // -14
Related API Elements
:: name qualifier | Operator |
namespace::property namespace::method() namespace::xmlObject.property namespace::xmlObject.@attribute |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Identifies the namespace of a property, a method, an XML property, or an XML attribute.
Operandsnamespace:Object —
The identifying namespace.
| |
propertyName:Object —
The property, method, XML property, or XML attribute to identify.
|
Example
How to use this example
The following example uses the
::
operator to identify two methods that have the same name in two different namespaces:
public class NamespaceExample extends Sprite { public namespace French; public namespace Hawaiian; public function NamespaceExample() { trace(Hawaiian::hello()); // aloha trace(French::hello()); // bonjour } Hawaiian function hello():String { return "aloha"; } French function hello():String { return "bonjour"; } }
::
operator to identify XML properties with specified namespaces:
var soap:Namespace = new Namespace("http://schemas.xmlsoap.org/wsdl/soap/"); var w:Namespace = new Namespace("http://weather.example.org/forecast"); var myXML:XML = <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <soap:Body> <w:forecast xmlns:w="http://weather.example.org/forecast"> <w:city>Quito</w:city> <w:country>Ecuador</w:country> <date>2006-01-14</date> </w:forecast> </soap:Body> </soap:Envelope>; trace(myXML.soap::Body.w::forecast.w::city); // Quito
Related API Elements
new | Operator |
|
Runtime Versions: | Flash Player 5 |
Instantiates a class instance. The new
operator can be used with a class or a variable of type Class to create an instance of a class.
The new
operator is commonly used with a class object to create an instance of a class. For example, the statement new Sprite()
creates an instance of the Sprite class.
The new
operator can also be used to associate a class with an embedded asset, which is an external object such as an image, sound, or font that is compiled into a SWF file.
Each embedded asset is represented by a unique embedded asset class. To access an embedded asset, you must use the new
operator to instantiate its associated class.
Subsequently, you can call the appropriate methods and properties of the embedded asset class to manipulate the embedded asset.
If you prefer to define classes with Function objects instead of the class
keyword, you can use the new
operator to create objects based on constructor functions.
Do not confuse constructor functions with constructor methods of a class. A constructor function is a Function object that is defined with the function
keyword, but that is not part of a class definition.
If you use constructor functions to create objects, you must use prototype inheritance instead of class inheritance.
constructor:* —
A class, a function, or a variable that holds a value of type Class.
| |
parameters:* —
One or more parameters, separated by commas.
|
Example
How to use this example
The following example creates the
Book
class and uses the new
operator to create the objects book1
and book2
.
class Book { var bName:String; var bPrice:Number; public function Book(nameParam:String, priceParam:Number){ bName = nameParam; bPrice = priceParam; } } var book1:Book = new Book("Confederacy of Dunces", 19.95); var book2:Book = new Book("The Floating Opera", 10.95); trace(book1); // [object Book]
new
operator to create an instance of the Array class with 18 elements:
var golfCourse:Array = new Array(18);
Related API Elements
{} object initializer | Operator |
object = {name1 : value1, name2 : value2,... nameN : valueN} |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Creates a new object and initializes it with the specified name
and value
property pairs. Using this operator is the same as using the new Object
syntax and populating the property pairs using the assignment operator. The prototype of the newly created object is generically named the Object object.
This operator is also used to mark blocks of contiguous code associated with flow control statements (for
, while
, if
, else
, switch
) and functions.
object:Object —
The object to create.
| |
name1,2,...N:Object —
The names of the properties.
| |
value1,2,...N:Object —
The corresponding values for each name property.
|
Object —
An Object object.
|
Example
How to use this example
The first line of the following code creates an empty object using the object initializer ({}) operator; the second line creates a new object using a constructor function:
var object:Object = {}; var object:Object = new Object();
account
and initializes the properties name
, address
, city
, state
, zip
, and balance
with accompanying values:
var account:Object = {name:"Adobe Systems, Inc.", address:"601 Townsend Street", city:"San Francisco", state:"California", zip:"94103", balance:"1000"}; for (i in account) { trace("account."+i+" = "+account[i]); }
var person:Object = {name:"Gina Vechio", children:["Ruby", "Chickie", "Puppa"]};
var person:Object = new Object(); person.name = "Gina Vechio"; person.children = new Array(); person.children[0] = "Ruby"; person.children[1] = "Chickie"; person.children[2] = "Puppa";
Related API Elements
() parentheses | Operator |
(expression1[, expression2]) (expression1, expression2) function(parameter1,..., parameterN) |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Usage 1: Controls the order in which the operators execute. Parentheses override the normal precedence order and cause the expressions within the parentheses to be evaluated first. When parentheses are nested, the contents of the innermost parentheses are evaluated before the contents of the outer ones.
Usage 2: Evaluates a series of expressions, separated by commas, in sequence, and returns the result of the final expression.
Usage 3: Surrounds one or more parameters and passes them to the function that precedes the parentheses.
Operandsexpression1:Object —
An expression, which can include numbers, strings, variables, or text.
| |
expression2:Object —
An expression, which can include numbers, strings, variables, or text.
| |
function:Function —
The function to be performed on the contents of the parentheses.
| |
parameter1...parameterN:Object —
A series of parameters to execute before the results are passed as arguments to the function outside the parentheses.
|
Example
How to use this example
Usage 1: The following statements show the use of parentheses to control the order in which expressions are executed:
trace((2 + 3) * (4 + 5)); // 45 trace(2 + (3 * (4 + 5))); // 29 trace(2 + (3 * 4) + 5); // 19 trace(2 + (3 * 4) + 5); // 19
foo()
and then the function bar()
, and returns the result of the expression a + b
:
var a:Number = 1; var b:Number = 2; function foo() { a += b; } function bar() { b *= 10; } trace((foo(), bar(), a + b)); // 23
var today:Date = new Date(); trace(today.getFullYear()); // outputs current year function traceParameter(param):void { trace(param); } traceParameter(2 * 2); // 4
Related API Elements
( ) parentheses (XML) | Operator |
myXML.(expression) |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Evaluates an expression in an ECMAScript for XML (E4X) XML construct. For example, myXML.(lastName == "Smith")
identifies XML elements with the name lastName
and the value "Smith"
. The result is an XMLList object.
myXML:* —
An XML or XMLList object.
| |
expression:* —
The expression defining the matching elements.
|
XMLList —
The XMLList specified by the parentheses.
|
Example
How to use this example
The following example shows how parentheses are used to identify elements and attributes:
var myXML:XML = <employees> <employee id = "42"> <firstName>Joe</firstName> <lastName>Smith</lastName> </employee> <employee id = "43"> <firstName>Susan</firstName> <lastName>Jones</lastName> </employee> <employee id = "44"> <firstName>Anne</firstName> <lastName>Smith</lastName> </employee> </employees>; trace(myXML.employee.(lastName == "Smith").@id.toXMLString()); // 42 // 44 trace(myXML.employee.(Number(@id) > 42).@id.toXMLString()); // 43 // 44
Related API Elements
/ RegExp delimiter | Operator |
/pattern/flags |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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. Note, however, that two sequential forward slash characters (//
) indicate the beginning of a comment.
pattern:String —
A sequence of one or more characters, defining the pattern of the regular expression.
| |
flags:String —
A sequence of zero or more of the following characters: g (for the global flag), i (for the ignoreCase flag), s (for the dotall flag), x (for the extended flag).
|
Example
How to use this example
The following example uses forward slash characters (/) to set the value of a variable of type RegExp (the
i
flag is set, to ignore case sensitivity when matching):
var myRegExp:RegExp = /foo-\d+/i; trace(myRegExp.exec("ABC Foo-32 def.")); // Foo-32
Related API Elements
=== strict equality | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Tests two expressions for equality, but does not perform automatic data conversion.
The result is true
if both expressions, including their data types, are equal.
The strict equality (===
) operator is the same as the equality (==
) operator in three ways:
- Numbers and Boolean values are compared by value and are considered equal if they have the same value.
- String expressions are equal if they have the same number of characters and the characters are identical.
- Variables representing objects, arrays, and functions are compared by reference. Two such variables are equal if they refer to the same object, array, or function. Two separate arrays are never considered equal, even if they have the same number of elements.
===
) operator differs from the equality (==
) operator in only two ways:
- The strict equality operator performs automatic data conversion only for the number types (Number, int, and uint), whereas the equality operator performs automatic data conversion for all primitive data types.
- When comparing
null
andundefined
, the strict equality operator returnsfalse
.
var x:Number = 1
) with primitive objects (for example, var x:Number = new Number(1)
).
This is because ActionScript 3.0 removes the distinction between primitive values and primitive wrapper objects.
First, comparisons between primitive values and primitive objects that contain the same value return true
in ActionScript 3.0, but false
in earlier versions. In earlier versions, the data type of a primitive value is either Boolean, Number, or String, whereas the data type of a primitive object is always Object rather than Boolean, Number or String.
The practical effect of this difference is that the following code results in false
in previous versions of ActionScript because the data types of the operands do not match, but the result is true
in ActionScript 3.0 because primitive values are typed as either Boolean, Number, int, uint, or String, whether they are wrapped in an object or not.
var num1:Number = 1; var num2:Number = new Number(1); trace(num1 === num2); // true in ActionScript 3.0, false in ActionScript 2.0
true
in ActionScript 3.0, but false
in previous versions.
var num1:Number = new Number(1); var num2:Number = new Number(1); trace(num1 == num2); // true in ActionScript 3.0, false in ActionScript 2.0 trace(num1 === num2); // true in ActionScript 3.0, false in ActionScript 2.0
false
for both the equality and strict equality operations.
In ActionScript 3.0, however, both variables belong to the data type Number, so they are compared by value and the result is true
for both the equality and strict equality operators.
Operandsexpression1:Object —
A number, string, Boolean value, variable, object, array, or function.
| |
expression2:Object —
A number, string, Boolean value, variable, object, array, or function.
|
Boolean —
The Boolean result of the comparison.
|
Example
How to use this example
The following example shows that strict equality (
===
) is the same as equality (==
) when both the value and data types match:
var string1:String = "5"; var string2:String = "5"; trace(string1 == string2); // true trace(string1 === string2); // true
==
) operator does:
// The equality (==) operator converts 5 to "5", but the strict equality operator does not var string1:String = "5"; var num:Number = 5; trace(string1 == num); // true trace(string1 === num); // false
var num:Number = 1; var bool:Boolean = true; trace(num == bool); // true trace(num === bool); // false
var num1:Number = 1; var num2:int = 1; var num3:uint = 1; trace(num1 === num2); // true trace(num1 === num3); // true
null
and undefined
not equal, but the equality operator considers them equal:
trace(null == undefined); // true trace(null === undefined); // false
Related API Elements
!== strict inequality | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Tests for the exact opposite of the strict equality (===
) operator.
The strict inequality operator performs the same as the inequality operator except that only the int and uint data types are converted.
If expression1
is equal to expression2
, and their data types are equal, the result is false
.
The strict inequality (!==
) operator is the same as the inequality (!=
) operator in three ways:
- Numbers and Boolean values are compared by value and are considered equal if they have the same value.
- String expressions are equal if they have the same number of characters and the characters are identical.
- Variables representing objects, arrays, and functions are compared by reference. Two such variables are equal if they refer to the same object, array, or function. Two separate arrays are never considered equal, even if they have the same number of elements.
!=
) operator in only two ways:
- The strict inequality (
!==
) operator performs automatic data conversion only for the number types, Number, int, and uint, whereas the inequality (!=
) operator performs automatic data conversion for all primitive data types. - When comparing
null
andundefined
, the strict inequality (!==
) operator returnstrue
.
expression1:Object —
A number, string, Boolean value, variable, object, array, or function.
| |
expression2:Object —
A number, string, Boolean value, variable, object, array, or function.
|
Boolean —
The Boolean result of the comparison.
|
Example
How to use this example
The comments in the following code show the returned value of operations that use the equality (
==
), strict equality (===
), and strict inequality (!==
) operators:
var s1:String = "5"; var s2:String = "5"; var s3:String = "Hello"; var n:Number = 5; var b:Boolean = true; trace(s1 == s2); // true trace(s1 == s3); // false trace(s1 == n); // true trace(s1 == b); // false trace(s1 === s2); // true trace(s1 === s3); // false trace(s1 === n); // false trace(s1 === b); // false trace(s1 !== s2); // false trace(s1 !== s3); // true trace(s1 !== n); // true trace(s1 !== b); // true
Related API Elements
" string delimiter | Operator |
"text" |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
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.
Operandstext:String —
A sequence of zero or more characters.
|
Example
How to use this example
The following example uses quotation marks (") to indicate that the value of the variable
yourGuess
is the literal string "Prince Edward Island"
and not the name of a variable.
var yourGuess:String = "Prince Edward Island"; submit_btn.onRelease = function() { trace(yourGuess); }; // Prince Edward Island
Related API Elements
- subtraction | Operator |
|
Runtime Versions: | Flash Player 9 |
Used for negating or subtracting.
Usage 1: When used for negating, the operator reverses the sign of a numerical expression.
Usage 2: When used for subtracting, the operator performs an arithmetic subtraction on two numerical expressions, subtracting expression2
from expression1
. When both expressions are integers, the difference is an integer. When either or both expressions are floating-point numbers, the difference is a floating-point number.
expression1:Number —
A number or expression that evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number.
|
Number —
An integer or floating-point number.
|
Example
How to use this example
Usage 1: The following statement reverses the sign of the expression 2 + 3:
trace(-(2 + 3)); // -5
trace(5 - 2); // 3
The following statement subtracts the floating-point number 1.5 from the floating-point number 3.25:
trace(3.25 - 1.5); // 1.75
-= subtraction assignment | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Assigns expression1
the value of expression1 - expression2
. For example, the following two statements are equivalent:
x -= y ; x = x - y;
String expressions must be converted to numbers; otherwise, the result is NaN
(not a number).
expression1:Number —
A number or expression that evaluates to a number.
| |
expression2:Number —
A number or expression that evaluates to a number.
|
Number —
The result of the arithmetic operation.
|
Example
How to use this example
The following example uses the subtraction assignment (
-=
) operator to subtract 10 from 5 and assign the result to the variable x
:
var x:Number = 5; var y:Number = 10; x -= y; trace(x); // -5
var x:String = "5"; var y:String = "10"; x -= y; trace(x); // -5
Related API Elements
: type | Operator |
[modifiers] var variableName:type function functionName():type { ... } function functionName(parameter1:type, ..., parameterN:type) [:type]{ ... } |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Used for assigning a data type; this operator specifies the variable type, function return type, or function parameter type. When used in a variable declaration or assignment, this operator specifies the variable's type; when used in a function declaration or definition, this operator specifies the function's return type; when used with a function parameter in a function definition, this operator specifies the variable type expected for that parameter.
Type checking always occurs at run time. However, when the compiler is set to strict mode, all types are also checked at compile time, and errors are generated when there is a mismatch. Mismatches can occur during assignment operations, function calls, and class member dereferencing using the dot (.
) operator.
Types that you can use include all native object types, classes and interfaces that you define, and void
. The recognized native types are Boolean, Number, int, uint, and String. All built-in classes are also supported as native types.
If you do not assign a data type, the variable, function return value, or function parameter is considered untyped, which means that the value can be of any data type. If you wish to make clear your intent to use an untyped value, you can use the asterisk (*) character as the type annotation. When used as a type annotation, the asterisk character is equivalent to leaving a variable, function return type, or function parameter untyped.
OperandsvariableName:* —
An identifier for a variable.
| |
type:* —
A native data type, class name that you have defined, or interface name.
| |
functionName:Function —
An identifier for a function.
| |
parameter:* —
An identifier for a function parameter.
|
Example
How to use this example
Usage 1: The following example declares a public variable named
userName
whose type is String and assigns an empty string to it:
var userName:String = "";
randomInt()
that specifies its return type as int:
function randomInt(integer:int):int { return Math.round(Math.random()*integer); } trace(randomInt(8));
squareRoot()
that takes a parameter named val
of the Number type and returns the square root of val
, also a Number type:
function squareRoot(val:Number):Number { return Math.sqrt(val); } trace(squareRoot(121));
Related API Elements
typeof | Operator |
|
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Evaluates expression
and returns a string specifying the expression's data type.
The result is limited to six possible string values: boolean
, function
, number
, object
, string
, and xml
.
If you apply this operator to an instance of a user-defined class, the result is the string object
.
The typeof
operator is included for backward compatibility. Use the is
operator to check type compatibility.
expression:Object —
An object to evaluate.
|
String —
A string representation of the type of expression . The following table shows the results of the typeof operator on each type of expression.
|
Example
How to use this example
The following example shows the result of using
typeof
on various objects and values.
trace(typeof Array); // object trace(typeof Date); // object trace(typeof 3); // number
new
operator to create an object.
This differs from previous versions of ActionScript in which the typeof
operator returns object
for variable b
:
var a:String = "sample"; var b:String = new String("sample"); trace(typeof a); // string trace(typeof b); // string
Related API Elements
void | Operator |
|
Runtime Versions: | Flash Player 9 |
Evaluates an expression and then discards its value, returning undefined
. The void
operator is often used in comparisons that use the ==
operator to test for undefined values.
expression:Object —
An expression to be evaluated.
|
* —
The value undefined .
|
< > XML literal tag delimiter | Operator |
myXML= <{tagName} {attributeName} = {attributeValue}>{content}{tagName}> |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9 |
Defines an XML tag in an XML literal. Use the forward slash / to define the closing tag.
OperandsmyXML:* —
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 this example
The following example shows how to use the
<
and >
operators when defining an XML literal:
var x:XML = <item id= "324">cola</item>;
Related API Elements
Wed Nov 21 2018, 07:01 AM -08:00