= (assignment)
119
Description
Operator; 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.
For more information, see
“Operator precedence and associativity” on page 32
.
Example
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
neptune
. Assignment by value is then used to assign the value of
49528 to the size property of the myObject 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
See also
== (equality)
Summary of Contents for FLEX-FLEX ACTIONSCRIPT LANGUAGE
Page 1: ...Flex ActionScript Language Reference...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Page 135: ...case 135 See also break default strict equality switch...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Page 808: ...808 Chapter 7 ActionScript for Flash...
Page 810: ...810 Appendix A Deprecated Flash 4 operators...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Page 822: ...822 Index...