Krinlon, you answered my previous question about arrays by showing how to get a reference to a variable out of an array, rather than its value. I did not understand your answer so I’m going to ask a more specific question and see if you can fill in the blanks for me.
Consider the following:
var incr:int = 0;
var arr:Array = [myFunction, getArgument];
function myFunction(arg):int {
return arg;
}
function getArgument():int {
return incr++;
}
trace(arr[0](arr[1])); // 0
trace(arr[0](arr[1])); // 0
trace(arr[0](arr[1])); // 0
I understand this happens because the second element of arr is simply a reference to the value returned by getArgument at the time the array is created. (Is that the best way to say that?)
But I want getArgument to be executed every time, so that::
trace(arr[0](arr[1])); // 0
trace(arr[0](arr[1])); // 1
trace(arr[0](arr[1])); // 2
How do I do that?