MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 94

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

When you change
because
otherNum
value of
that it receives (in line 2 of the code).
myNum
3.
Select Control > Test Movie to see the values display in the Output panel.
4.
Now add the following ActionScript after the code you added in step 2:
function sqr(myNum:Number):Number {
myNum *= myNum;
return myNum;
}
var inValue:Number = 3;
var outValue:Number = sqr(inValue);
trace(inValue); // 3
trace(outValue); // 9
In the this code, the variable
the
function, and the returned value is
sqr()
not change, although the value of
5.
Select Control > Test Movie to see the values display in the Output panel.
The Object data type can contain such a large amount of complex information that a variable
with this type doesn't hold an actual value; it holds a reference to a value. This reference is
similar to an alias that points to the contents of the variable. When the variable needs to know
its value, the reference asks for the contents and returns the answer without transferring the
value to the variable.
For information on passing a variable by reference, see
on page
94.
Passing a variable by reference
Because the Array and Object data types hold a reference to a value instead of containing its
actual value, you need be careful when you work with arrays and objects.
The following example shows how to pass an object by reference. When you create a copy of
the array, you actually create only a copy of the reference (or alias) to the array's contents.
When you edit the contents in the second array, you modify both the contents of the first and
second array because they both point to the same value.
94
Data and Data Types
to 30 (in line 3 of the code), the value of
myNum
doesn't look to
myNum
contains a primitive value,
inValue
myNum
for its value. The
otherNum
. The value of the variable
9
in the function changes.
"Passing a variable by reference"
remains
otherNum
15
variable contains the
, so the value passes to
3
does
inValue

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents