Skip to main content
Participant
August 2, 2013
Answered

Going to a random frame

  • August 2, 2013
  • 1 reply
  • 459 views

So I try to make my program go to a random slide.

So I put this code

{gotoAndPlay(155+function fl_GenerateRandomNumber_2(limit:Number):Number

{

    var randomNumber:Number = Math.floor(Math.random()*(limit+1));

    return randomNumber;

}

trace(fl_GenerateRandomNumber_2(4));)} 

In this case, I want the program to go to the frame from 155-159 (randomly)

The error is

-expecting rightparen before trace

-expecting rightbrace before rightparen

Question #1

1) Ok. I realieze my mistake, It got to be those brackets family. But I can't figure out which one is wrong.

2) If those 2 error edited, will this code actually works? If it is not. Is there any alternative?

Thanks

This topic has been closed for replies.
Correct answer kglad

use:

gotoAndPlay(randomF(155,159));

function randomF(n1:int,n2:int):int{

return n1-1+Math.ceil(Math.random()*(n2-n1));

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 2, 2013

use:

gotoAndPlay(randomF(155,159));

function randomF(n1:int,n2:int):int{

return n1-1+Math.ceil(Math.random()*(n2-n1));

}