the code below is a much simplified version but it duplicates the mysterious error. below i trace the contents of genesArray using a function and all of the cells are different, but when i trace it again they are all the same. i am truly baffled as to why.
package {
import flash.display.MovieClip;
public class GMachine extends MovieClip{
private var randomArray:Array;
private var total:int;
private var rndm:int;
private var genesArray:Array;
public function GMachine(){
randomArray = new Array();
genesArray = new Array();
total = 5;
makeGenes();
}
private function randomArrayGenerator():Array{
for(var i:int = 0; i < total; i++){
rndm = Math.random()*10;
randomArray* = rndm;
}
return randomArray;
}
private function makeGenes():void{
trace("here they are different");
for(var i:int = 0; i < total; i++){
genesArray* = randomArrayGenerator();
traceArray(genesArray*);
}
trace("why are these the same?");
for(i = 0; i < total; i++){
traceArray(genesArray*);
}
}
private function traceArray(inArray:Array):void{
var tmpStr:String = "";
for(var j:int = 0; j < inArray.length; j++){
tmpStr+=inArray[j]+" ";
}
trace(tmpStr);
}
}
}
sample output:
here they are different
9 0 2 6 5
6 1 0 5 9
7 4 1 1 7
3 3 0 6 0
0 9 7 4 6
why are these the same?
0 9 7 4 6
0 9 7 4 6
0 9 7 4 6
0 9 7 4 6
0 9 7 4 6