Does not go to page currently on, randomly goes to another page.
Code:
function randNum(nMin, nMax) {
return Math.round(Math.random() * (nMax - nMin)) + nMin;
}
pil2.onRelease = function() {
s = new Sound();
s.attachSound("knack");
s.start();
newLoc = "go" + randNum(1, 6);
while (curLoc == newLoc) {
newLoc = "go" + randNum(1, 6);
}
curLoc = newLoc;
_root.gotoAndStop(newLoc);
};
- or -
Randomly goes to each page, then stops.
Code:
function randNum(nMin, nMax) {
return Math.round(Math.random() * (nMax - nMin)) + nMin;
}
var rndArray = new Array();
var i = 0;
while (i++ < 6) {
rndArray.splice(randNum(0, rndArray.length),0,"go" + i);
}
trace(rndArray);
/////
pil2.onRelease = function() {
s = new Sound();
s.attachSound("knack");
s.start();
_root.gotoAndStop(rndArray.pop());
}