Jumping to a random label, scene, frame without repetition
1. define a label in every frame you want to jump randomly
2. use the following script:
//before you can start the game, the framenumbers have to be putted in the list
//the parameter finishedFrame is a framelabel which is returned, when the list is done.
function initLabels(finishedFrame){
labelarray=[finishedFrame,"label1","label2","label3","label4"];
}
//anywhere inside your swf you can call this function to get the next framelabel
//if the list is empty, the value of finishedFrame is returned
function getNextLabel(){
var randomIdx, returnValue;
if(labelarray.length > 1){
randomIdx = Math.floor(Math.random() * labelarray.length + 1);
returnValue = labelarray[randomIdx];
labelarray.splice(randomIdx,1);
return (returnValue)
} else {
return labelarray[0];
}
}
//init the list - at the end jump to frameLabel "TheEnd"
initLabels("TheEnd");
//jump to the first randomly picked question
gotoAndStop(getNextLabel());
- tim Date: 18/07/2001
The first argument in the splice function should be \"randomIdx\" and not idx.
Tim.
- lharby Date: 20/08/2004
I kinda got this to work, except that it is repeating frames before going through the entire array.
e.g. A,A,A,D
I want A,D,C,B etc. before A is played again?
Apologies if I shouldn't be posting here.
Add comment
Home