Highlighted

Random Frame

New Here ,
Feb 23, 2017

Copy link to clipboard

Copied

I have identified a button.

This button was going to the next frame.

But I want a random frame.

Would you like to see sample code.

thank you so much

Say your button has instance name randomFrameBtn, add this code (adapt the minFrameNb and maxFrameNb to your timeline) :

randomFrameBtn.addEventListener( MouseEvent.CLICK, goToRandomFrame);

function goToRandomFrame( event:MouseEvent): void

{

    var minFrameNb = 5;

    var maxFrameNb = 20;

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

    gotoAndStop( randomFrameNb);

}

Views

1.7K

Likes

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

Random Frame

New Here ,
Feb 23, 2017

Copy link to clipboard

Copied

I have identified a button.

This button was going to the next frame.

But I want a random frame.

Would you like to see sample code.

thank you so much

Say your button has instance name randomFrameBtn, add this code (adapt the minFrameNb and maxFrameNb to your timeline) :

randomFrameBtn.addEventListener( MouseEvent.CLICK, goToRandomFrame);

function goToRandomFrame( event:MouseEvent): void

{

    var minFrameNb = 5;

    var maxFrameNb = 20;

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

    gotoAndStop( randomFrameNb);

}

Views

1.7K

Likes

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
Feb 23, 2017 0
Adobe Community Professional ,
Feb 23, 2017

Copy link to clipboard

Copied

What software are you using?

Likes

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
Reply
Loading...
Feb 23, 2017 0
New Here ,
Feb 23, 2017

Copy link to clipboard

Copied

Animate CC

I have just started and I haven't any information about coding

Likes

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
Reply
Loading...
Feb 23, 2017 0
Adobe Community Professional ,
Feb 23, 2017

Copy link to clipboard

Copied

I'm going to move your post over to the Animate forum. The Coding Corner​ forum is more for general coding stuff whereas the Animate forum folk will be able to offer you more specific help for Animate.

Likes

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
Reply
Loading...
Feb 23, 2017 0
Adobe Community Professional ,
Feb 23, 2017

Copy link to clipboard

Copied

Code to go to the next frame might look like this:

this.gotoAndStop(this.currentFrame+1);

Code to go a frame that is up to 10 frames ahead of where you are now would look like this:

this.gotoAndStop(this.currentFrame+Math.random()*10);

If you wanted to jump to a random frame starting at 15 and ending at 25, it would be like this:

this.gotoAndStop(15+Math.random()*10);

Math.random() gives you a value between 0 and almost 1. Multiplying that by 10 would make the number be from 0 to almost 10.

Likes

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
Reply
Loading...
Feb 23, 2017 1
Adobe Community Professional ,
Feb 23, 2017

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Feb 23, 2017 0
Enthusiast ,
Feb 24, 2017

Copy link to clipboard

Copied

A downloadable example of playing the different frames/states of a timeline in random order here :

https://forums.adobe.com/message/9309084#9309084

Likes

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
Reply
Loading...
Feb 24, 2017 1