views:

35

answers:

1

i would like to update the numbers i've added to an array from variables, when those variables change. is it possible change these variables and have the array update automatically?

var first:Number = 1;
var second:Number = 2;

var myArray:Array = new Array(first, second);

first = 3;
second = 4;

trace(myArray) //outputs 1,2
+2  A: 

Instead of storing a primitive type ( Number ), use an Object to wrap Number. Something like this pseudo-code:

var first:Object = { value: 1 };
var second:Object = { value: 2 };

var array:Array = [ first, second ];

first.value = 3;
second.value = 4;
jeremynealbrown