Rand
05-15-2010, 09:44 PM
Hello All,
I am trying to randomize some photos as they appear in a static gallery. I can do it easily, except that the numbers I pull from the the array below sometimes appear as NaN (Not a Number). In fact, if you run the routine below a few times, the results will change variably each time you run it. Some numbers will be NaN, and some won't.
I have tried to push the results through the Number() function, and while that works to a degree, I find that I cannot ultimately perform math on them when I do it that way. That is, I could not add 1 to a variable that just tested as a number.
I would certainly be grateful if you could point me in the right direction. I am sure this is simple for you pros.
Thank you!
Rand
myArray = new Array(0,1,2,3,4,5,6,7,8,9,10,11);
Array.prototype.shuffle = function(){
for (i=0; i < this.length; i++){
this.push(this.splice(Math.floor(Math.random() * this.length), 1));
}
}
myArray.shuffle();
_global.rand_photo_place0=myArray[0];
trace(rand_photo_place0);
trace(isNaN(rand_photo_place0));
_global.rand_photo_place1=myArray[1];
trace(rand_photo_place1);
trace(isNaN(rand_photo_place1));
_global.rand_photo_place2=myArray[2];
trace(rand_photo_place2);
trace(isNaN(rand_photo_place2));
_global.rand_photo_place3=myArray[3];
trace(rand_photo_place3);
trace(isNaN(rand_photo_place3));
_global.rand_photo_place4=myArray[4];
trace(rand_photo_place4);
trace(isNaN(rand_photo_place4));
_global.rand_photo_place5=myArray[5];
trace(rand_photo_place5);
trace(isNaN(rand_photo_place5));
_global.rand_photo_place6=myArray[6];
trace(rand_photo_place6);
trace(isNaN(rand_photo_place6));
I am trying to randomize some photos as they appear in a static gallery. I can do it easily, except that the numbers I pull from the the array below sometimes appear as NaN (Not a Number). In fact, if you run the routine below a few times, the results will change variably each time you run it. Some numbers will be NaN, and some won't.
I have tried to push the results through the Number() function, and while that works to a degree, I find that I cannot ultimately perform math on them when I do it that way. That is, I could not add 1 to a variable that just tested as a number.
I would certainly be grateful if you could point me in the right direction. I am sure this is simple for you pros.
Thank you!
Rand
myArray = new Array(0,1,2,3,4,5,6,7,8,9,10,11);
Array.prototype.shuffle = function(){
for (i=0; i < this.length; i++){
this.push(this.splice(Math.floor(Math.random() * this.length), 1));
}
}
myArray.shuffle();
_global.rand_photo_place0=myArray[0];
trace(rand_photo_place0);
trace(isNaN(rand_photo_place0));
_global.rand_photo_place1=myArray[1];
trace(rand_photo_place1);
trace(isNaN(rand_photo_place1));
_global.rand_photo_place2=myArray[2];
trace(rand_photo_place2);
trace(isNaN(rand_photo_place2));
_global.rand_photo_place3=myArray[3];
trace(rand_photo_place3);
trace(isNaN(rand_photo_place3));
_global.rand_photo_place4=myArray[4];
trace(rand_photo_place4);
trace(isNaN(rand_photo_place4));
_global.rand_photo_place5=myArray[5];
trace(rand_photo_place5);
trace(isNaN(rand_photo_place5));
_global.rand_photo_place6=myArray[6];
trace(rand_photo_place6);
trace(isNaN(rand_photo_place6));