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

Random number = random scene

New Here ,
Jul 30, 2019 Jul 30, 2019

Copy link to clipboard

Copied

Hi there, I am having a little trouble figuring out how to correctly format this. The quotes turn the text green and normally you would hard code what scene you want to travel too. I want the scene to be "Scene X" where X = random number between 2 - 5

stop();

button_next.addEventListener( MouseEvent.CLICK, goToRandomFrame);

function goToRandomFrame( event:MouseEvent): void

{

    var minFrameNb = 2;

    var maxFrameNb = 5;

    var randomFrameNb = minFrameNb +Math.floor( Math.random() * (maxFrameNb - minFrameNb + 1));

    gotoAndPlay(1, "goToRandomFrame");

}

Views

586

Translate

Translate

Report

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

Engaged , Jul 31, 2019 Jul 31, 2019

Hi,

You just need to compose the name of the scene.

In the example, that I have attached, my scenes are called "Scene 1", "Scene 2"... and so on.

In the event handler function, I compose the scene name using the random number. That's all! 🙂

this.stop(); 

 

 

button_next.addEventListener( MouseEvent.CLICK, goToRandomFrame); 

 

function goToRandomFrame( event:MouseEvent): void {

    var minFrameNb:Number  = 2; 

    var maxFrameNb:Number = 5; 

    var randomFrameNb:Number = minFrameNb + Math.floor( Ma

...

Votes

Translate

Translate
Engaged ,
Jul 31, 2019 Jul 31, 2019

Copy link to clipboard

Copied

Hi,

You just need to compose the name of the scene.

In the example, that I have attached, my scenes are called "Scene 1", "Scene 2"... and so on.

In the event handler function, I compose the scene name using the random number. That's all! 🙂

this.stop(); 

 

 

button_next.addEventListener( MouseEvent.CLICK, goToRandomFrame); 

 

function goToRandomFrame( event:MouseEvent): void {

    var minFrameNb:Number  = 2; 

    var maxFrameNb:Number = 5; 

    var randomFrameNb:Number = minFrameNb + Math.floor( Math.random() * (maxFrameNb - minFrameNb + 1));

    var sceneName:String = "Scene " + String( randomFrameNb );

    gotoAndPlay( 1, sceneName );

}

https://cloud.vectorworks.net/links/11e9b36e667b104c82270a7c60cb7e10/

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

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
New Here ,
Jul 31, 2019 Jul 31, 2019

Copy link to clipboard

Copied

LATEST

Thankyou, works perfectly. A+

Votes

Translate

Translate

Report

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