setup variables on the main timeline:
whichfile=Math.round(Math.random()*3+1); // pick a number between 1 and 3, round it off.
savefile=whichfile;
for the button:[AS]on(release){
getURL(“test”+_root.whichfile+".htm", “mainFrame”);
_root.savefile=_root.whichfile; // remember which file
trace(_root.whichfile); // which file should be opening
_root.whichfile=Math.round(Math.random()*3+1);
if ((_root.whichfile==_root.savefile) and (_root.whichfile!=3));{
whichfile+=1;
}
else if ((_root.whichfile==_root.savefile) and (_root.whichfile==3)){
_root.whichfile=Math.round(Math.random()*2+1);
}
}[/AS]
Just some question… How can I change the number of random files chosen? What does the ‘if, whichfile+=1;’ and ‘else if, _root.whichfile = Math.round(Math.random()*2+1);’ mean?
sorry, i didn’t really comment that code. so here it is commented.[AS]on(release){
getURL(“test”+_root.whichfile+“.htm”, “mainFrame”);
_root.savefile=_root.whichfile; // remember which file
trace(_root.whichfile); // which file should be opening
_root.whichfile=Math.round(Math.random()*3+1); // select new file randomly
if ((_root.whichfile==_root.savefile) and (_root.whichfile!=3));{ // if newly selected file is repeat of old file but not the last file in group
whichfile+=1; // add one to new file
}
else if ((_root.whichfile==_root.savefile) and (_root.whichfile==3)){ // if newly selected file is repeat of old file and is last file in group
_root.whichfile=Math.round(Math.random()*2+1); reselect new file randomly from a range of first file to (last file-1)
}
}[/AS]basically, that ending bit of code ensures that files aren’t repeated. the savefile variable just lets us compare our new value for whichfile to our old value. if it’s a repeat, we reselect a new whichfile, either by adding 1 or doing it randomly again.
to change the total number of files, find the 3’s in there and make them whatever number you want (ie 10 for 10 files). even better would be to replace all the 3’s with _root.totalfiles . then in the main timeline, setup a variable named totalfiles=10; this would make it easier to change in the future (because instead of changing all the 3’s, you’d only be changing one variable on the main timeline). you would also have to change the _root.whichfile=Math.round(Math.random()2+1); part of the button AS to _root.whichfile=Math.round(Math.random()(totalfiles-1)+1);
// i don’t know what’s going on, but in the AS just above, preview post is showing me a space between the L and E of totalfiles. there should be no space. it won’t let me change it for whatever reason.
if repeating doesn’t matter to you, you could take out everything after the //select new file randomly (remember to keep the last } though).