View Full Version : Going to a random frame
ChaosEmerl
07-31-2006, 07:22 AM
Basically, what I want is, on the click of a button, the movie to go to a random frame. Here's what I have:
on (release) {
var say;
say = random(4);
if (say = "0") {
gotoAndStop(2);
}
else if (say = "1") {
gotoAndStop(3);
}
else if (say = "2") {
gotoAndStop(4);
}
else if (say = "3") {
gotoAndStop(5);
}
}
That seems like it should work, but it doesn't. It always goes to frame 3, no matter what I set the variable as. Is there something I'm missing here? Am I going about this the completely wrong way?
FormerSwinger
07-31-2006, 08:51 AM
HI
There's a couple of things that cause your script to fail. First the random number is not a String so lose the quotes. Second the you are not assigning a new value so add a second = sign.
I'd do like this:
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.round(Math.random()*(max-min))+min;
return randomNum;
}
on (release) {
var say;
say = randRange(2,5);
gotoAndStop(say);
}
ChaosEmerl
07-31-2006, 08:42 PM
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.round(Math.random()*(max-min))+min;
return randomNum;
}
on (release) {
var say;
say = randRange(2,5);
gotoAndStop(say);
}
Am I supposed to replace "number" with anything? Because that script doesn't work. Might note that I'm using Flash MX (6) so some of those commands might not be in that version.
FormerSwinger
08-01-2006, 11:16 AM
Don't know about version six. Try removing the variable types:
function randRange(min, max){
var randomNum= Math.round(Math.random()*(max-min))+min;
return randomNum;
}
on (release) {
var say;
say = randRange(2,5);
gotoAndStop(say);
}
ChaosEmerl
08-02-2006, 02:32 AM
Thanks. Worked perfectly. Just had to move the "on (release) {" to the beginning.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.