Question
help "mr can't program for toffee" with his array
hey people,
i posted this topic a few days back and had a great response but can't seem to make the code
supplied work...
my current code is
var randomMax:Number = 10;
var randomMin:Number = 1;
var randomFileNum:Number = Math.floor(Math.random() * randomMax + randomMin);
trace(randomFileNum); //will display from 1 to 10;
loadMovieNum(randomFileNum + ".swf", 1);
THIS WORKS GREAT EXCEPT FOR THE RANDOM REPEATS which i need to
eliminate
if someone wouldn't mind scripting the whole code for me (Coz i'm thick)
with the assumption that the files i want to shuffle are called
301.swf
302.swf
303.swf
304.swf
305.swf
306.swf
307.swf
help me obi won kenobi, your my only hope....
THIS WAS THE POSTED SOLUTION :
---------------------------------------------------------------------------------------------------------------
easiest just to make an array of the numbers you need and shuffle it.
//And ths code to add the shuffle method to the array class
Array.prototype.shuffle = function() {
var i:Number;
this.sort(function(a,b) { i = Math.round((Math.random() * 100) - 50); return i;});
return this;
};
var fileNum_array = [];//declare empty array
for( var i=randomMin;i<=randomMax;i++)
{
fileNum_array.push(i);
}
fileNum_array.shuffle();
then pull the values out of the array incrementally
loadMovieNum(fileNum_array[0] + ".swf", 1);
loadMovieNum(fileNum_array[1] + ".swf", 1);
loadMovieNum(fileNum_array[2] + ".swf", 1);
etc...
or use an incrementing variable everytime you need to return a value
var myIncVar = 0;
loadMovieNum(fileNum_array[myIncVar++] + ".swf", 1);
loadMovieNum(fileNum_array[myIncVar++] + ".swf", 1);
etc...
Hope that helped, Ade
i posted this topic a few days back and had a great response but can't seem to make the code
supplied work...
my current code is
var randomMax:Number = 10;
var randomMin:Number = 1;
var randomFileNum:Number = Math.floor(Math.random() * randomMax + randomMin);
trace(randomFileNum); //will display from 1 to 10;
loadMovieNum(randomFileNum + ".swf", 1);
THIS WORKS GREAT EXCEPT FOR THE RANDOM REPEATS which i need to
eliminate
if someone wouldn't mind scripting the whole code for me (Coz i'm thick)
with the assumption that the files i want to shuffle are called
301.swf
302.swf
303.swf
304.swf
305.swf
306.swf
307.swf
help me obi won kenobi, your my only hope....
THIS WAS THE POSTED SOLUTION :
---------------------------------------------------------------------------------------------------------------
easiest just to make an array of the numbers you need and shuffle it.
//And ths code to add the shuffle method to the array class
Array.prototype.shuffle = function() {
var i:Number;
this.sort(function(a,b) { i = Math.round((Math.random() * 100) - 50); return i;});
return this;
};
var fileNum_array = [];//declare empty array
for( var i=randomMin;i<=randomMax;i++)
{
fileNum_array.push(i);
}
fileNum_array.shuffle();
then pull the values out of the array incrementally
loadMovieNum(fileNum_array[0] + ".swf", 1);
loadMovieNum(fileNum_array[1] + ".swf", 1);
loadMovieNum(fileNum_array[2] + ".swf", 1);
etc...
or use an incrementing variable everytime you need to return a value
var myIncVar = 0;
loadMovieNum(fileNum_array[myIncVar++] + ".swf", 1);
loadMovieNum(fileNum_array[myIncVar++] + ".swf", 1);
etc...
Hope that helped, Ade
