I think it would be simplest to explain it like this:
num1 = arr2[upTo][0];
trace(num1);
Output: 0
trace(arr2[upTo][0]);
Output: Correct number
where arr2 is a shuffled array.
My code:
public class Main extends MovieClip {
var num1:int;
var num2:int;
var scoreArr:Array = new Array();
var upTo:int = 0;
var arr2:Array = new Array();
public function Main() {
for (var i = 1; i <= 9; i++) {
for (var j = 1; j <= 9; j++) {
scoreArr.push([i,j]);
}
}
while (scoreArr.length > 0) {
arr2.push(scoreArr.splice(Math.round(Math.random() * (scoreArr.length - 1)), 1));
}
newQ();
}
private function newQ():void {
num1 = arr2[upTo][0];
num2 = arr2[upTo][1];
trace(num1); //outputs: 0
trace(arr2[upTo][1]); //outputs: correct number
}
It seems datatypes are different and trace is ignoring the datatype while displaying.
and num1 is converting that datatype into int while getting assigned, turning into 0.
can you try comparing typeof arr2[upTo][0] and num1 ?
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/operators.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6#typeof
One more thing I noticed in your code :