Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript language elements > Operators > = assignment operator | |||
expression1 = expression2
Assigns the value of expression2 (the parameter 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 a variable is assigned a number or string literal. Assignment by reference stores a reference to expression2 in expression1. Assignment by reference is commonly used with the new operator. Use of the new operator creates an object in memory and a reference to that location in memory is assigned to a variable.
Availability: ActionScript 1.0; Flash Player 4 - In Flash 4, = is a numeric equality operator. In Flash 5 or later, = is an assignment operator, and the == operator is used to evaluate equality. Flash 4 files that are brought into the Flash 5 or later authoring environment undergo a conversion process to maintain data type integrity.
Flash 4 file: x = y
Converted Flash 5 or later file: Number(x) == Number(y)
expression1 : Object - A variable, element of an array, or property of an object.
expression2 : Object - A value of any type.
Object - The assigned value, expression2 .
The following example uses assignment by value to assign the value of 5 to the variable x.
var x:Number = 5;
The following example uses assignment by value to assign the value "hello" to the variable x:
var x:String; x = " hello ";
The following example uses assignment by reference to create the moonsOfJupiter variable, which contains a reference to a newly created Array object. Assignment by value is then used to copy the value "Callisto" to the first element of the array referenced by the variable moonsOfJupiter:
var moonsOfJupiter:Array = new Array(); moonsOfJupiter[0] = "Callisto";
The following example uses assignment by reference to create a new object, and assign a reference to that object to the variable mercury. Assignment by value is then used to assign the value of 3030 to the diameter property of the mercury object:
var mercury:Object = new Object(); mercury.diameter = 3030; // in miles trace (mercury.diameter); // output: 3030
The following example builds upon the previous example by creating a variable named merkur (the German word for mercury) and assigning it the value of mercury. This creates two variables that reference the same object in memory, which means you can use either variable to access the object's properties. We can then change the diameter property to use kilometers instead of miles:
var merkur:Object = mercury; merkur.diameter = 4878; // in kilometers trace (mercury.diameter); // output: 4878
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001251.html