I need to generate 3 unique numbers that will allow me to call from an array that has a list of FLVs with links, title and maybe a description. I know how to make random numbers but i need to know how to make sure that they are not doubling up so i can have [1,8,0] but not [1,8,1]. i will attach all my files and let someone take a look and see if they understand what i am doing.
What i am trying to do is in the chooser.fla is randomly fill the empty movieClips and then i want to build in a timer that will refresh the movieClips with fresh images.
i would do it by making an array of possible numbers, then selecting 3 of those numbers, but each time splicing out that number so it can’t be choosen again.
var temp_array:Array = new Array();
var choosenNumbers:Array = new Array();
for (i=0; i<10; i++) {
temp_array.push(i);
}
for (j=0; j<3; j++) {
var index:Number = Math.floor(Math.random()*temp_array.length);
choosenNumbers.push(temp_array[index]);
temp_array.splice(index, 1);
}
trace(choosenNumbers);
some people would make the temp array and shuffle function to shuffle the array and then just take the first 3 elements
Thank you very much that worked well. Now i am wondering what i would need to do to have that array reload with 3 new numbers after a 5 sec timer. Here is what i have now
myInterval = setInterval(doSomething, 5000) // 1000 represents 1 second
function doSomething(){
choosenNumbers.splice(0,3);
getImage();
}
This is the getImage function:
function getImage(){
//create MC
this.createEmptyMovieClip("vid10", this.getNextHighestDepth());
vid10.createEmptyMovieClip("vid11", this.getNextHighestDepth());
this.createEmptyMovieClip("vid20", this.getNextHighestDepth());
vid20.createEmptyMovieClip("vid21", this.getNextHighestDepth());
this.createEmptyMovieClip("vid30", this.getNextHighestDepth());
vid30.createEmptyMovieClip("vid31", this.getNextHighestDepth());
//load images
for (i=0; i<images.length; i++) {
temp_array.push(i);
}
for (j=0; j<3; j++) {
var index:Number = Math.floor(Math.random()*temp_array.length);
choosenNumbers.push(temp_array[index]);
temp_array.splice(index, 1);
}
trace(choosenNumbers);
myInterval = setInterval(doSomething, 5000) // 1000 represents 1 second
function doSomething(){
choosenNumbers.splice(0,3);
getImage();
}
mcl.loadClip(images[temp_array[0]][1], "vid10.vid11");
mcl.loadClip(images[temp_array[1]][1], "vid20.vid21");
mcl.loadClip(images[temp_array[2]][1], "vid30.vid31");
//pics location
vid10._x = 38.5
vid10._y = 57.5
vid20._x = 179.5
vid20._y = 57.5
vid30._x = 320.5
vid30._y = 57.5
}