Nicolas Pirson :
Go to my website : tatactic.be [FR] (Website about hepatitis)
nicolas.pirson.me [FR - EN] (current website)
business card - blog
[FR - EN] (just for fun)
Nicolas Pirson CV page [FR] on tatactic.be
Back to AS3 - FLASH index ... [EN]
in AS3 :
Package Top Level
Class public dynamic class Array
Inheritance Array Object
(Object is a dynamic class too : public dynamic class Object)
So an Array is an Object too...
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html
MyArray = [];
// or MyArray = new Array();
myNewArray = MyArray;
trace("instanceof Array or is Array in AS3 ? -> " + (myNewArray instanceof Array));
trace("instanceof Object or is Object in AS3 ? -> " + (myNewArray instanceof Object));
/*
This is a reference to MyArray not an instance of a new Array
So if you change something to myNewArray, MyArray will be modified too.
let's take a look at this...
*/
myNewArray[0] = "Some Value";
trace("myNewArray[0] = " + myNewArray[0]);
//Outputs "Some Value"
//this looks fine BUT :
trace("MyArray[0] = " + MyArray[0]);
// Outputs the same as above ("Some Value")
/*
This is NOT a reference to MyArray but a new Array
So if you change something to myNewArray, MyArray will NOT be modified.
let's take a look at this...
*/
myNewArray[0] = "Some Value";
trace("myNewArray[0] = " + myNewArray[0]);
//Outputs "Some Value"
trace("MyArray[0] = " + MyArray[0]);
// Outputs : "Default value"
MyArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
// or MyArray = new Array();
myNewArray = MyArray.slice();
/*
This is NOT a reference to MyArray but a new Array
So if you change something to myNewArray, MyArray will NOT be modified.
let's take a look at this...
*/
trace("myNewArray = " + myNewArray);
//output : 1,2,3,4,5,6,7,8,9
myNewArray = [2, 6, 4, 1, 7, 5, 3, 9, 8, 6];
trace("myNewArray (modified) = " + myNewArray);
// output : 2,6,4,1,7,5,3,9,8,6
trace("MyArray = " + MyArray);
// Outputs 1,2,3,4,5,6,7,8,9 so it's fine, it's not a reference anymore