views:

29

answers:

3
var array1:Array = new Array();
var array2:Array = new Array();

var obj1:Object = new Object();

array1.push(obj1);
array2.push(obj1);


if i change something in obj1 will array1[0] and array2[0] also change?
A: 

Yes. In ActionScript 3.0, all arguments are passed by reference. Therefore, you are passing the reference to the obj1 onto both arrays. Changing a value in the object will be reflected in array1 and array2.

jcsf
A: 

yes. it will change.

ReBeL
A: 

You have two lists, both storing names of students in a class - say, one in alphabetical order and other in the order of their age. If a student clears one examination, does the corresponding student in both lists clear the exam or only one of them?

Both refer to the same student - same student Object.

Now say you wrote down the mark of a student from his answer sheet to some paper. If the student erases and updates the value on that paper, does his real mark change? No, because that was just a copied value of the mark. This is analogous to copying student.mark to a numeric variable and changing it.

Amarghosh