Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Going to a random frame

New Here ,
Aug 02, 2013 Aug 02, 2013

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

TOPICS
ActionScript
433
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 02, 2013 Aug 02, 2013

use:

gotoAndPlay(randomF(155,159));

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

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

}

Translate
Community Expert ,
Aug 02, 2013 Aug 02, 2013
LATEST

use:

gotoAndPlay(randomF(155,159));

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

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines