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

Help with making a button script

Community Beginner ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

I need help for a Project, I want to make a button when pressed will go to another frame example it's at frame 20 and when pressed goes straight to frame 21 but if it's not pressed it keeps looping example once it gets to frame 20 it goes back to frame 10 and keeps repeating until pressed.

Views

201

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

Community Expert , Jul 16, 2020 Jul 16, 2020

Hi.

 

If I'm understanding what you want, you need to store the final frame of your animation in a property or variable. Then when the user presses the button, you change the value of this property or variable. Like this:

 

HTML5 Canvas:

Main timeline / frame 1 (0):

var root = this;

root.endFrame = 9; // in HTML5 documents the first frame index is 0 so the 10th frame index is 9

root.stopLoop = function(e)
{
	root.endFrame = 19;
};

root.yourButton.on("click", root.stopLoop);

 

Main timeline /

...

Votes

Translate

Translate
Community Expert ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

Did you also stop the timeline? If looping until you press the button you likely haven't stopped the timeline previous to that. Maybe I'm not understanding the issue though - please provide visuals or a code example.

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
Community Beginner ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

I'm still new to animate and learning how to use code but all I want to do is create a loop in my timeline and have a button when pressed will stop the loop  and continue playing the timeline 

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
Community Beginner ,
Jul 15, 2020 Jul 15, 2020

Copy link to clipboard

Copied

So when I start playing my animation once it reaches frame 20 it will loop back to frame 10 and keep playing and looping until the user pressed the button undoing the loop and playing what's after frame 20. Because I'm making a game where you have to warn the character by clicking on it and if you don't warn it, it will get hit by a car and then loop back again to the start of the scene and keep playing and once you warn the character it will stop the loop and take you to another frame where it shows him stopping evading the car. It's like the game Crossy road

 

 

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
Community Expert ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

Hi.

 

If I'm understanding what you want, you need to store the final frame of your animation in a property or variable. Then when the user presses the button, you change the value of this property or variable. Like this:

 

HTML5 Canvas:

Main timeline / frame 1 (0):

var root = this;

root.endFrame = 9; // in HTML5 documents the first frame index is 0 so the 10th frame index is 9

root.stopLoop = function(e)
{
	root.endFrame = 19;
};

root.yourButton.on("click", root.stopLoop);

 

Main timeline / frame 10 (9):

this.gotoAndPlay(this.endFrame);

 

AS3:

Main timeline / frame 1:

import flash.events.MouseEvent;

var endFrame:uint = 10;

function stopLoop(e:MouseEvent):void
{
	endFrame = 20;
}

yourButton.addEventListener(MouseEvent.CLICK, stopLoop);

 

Main timeline / frame 10:

gotoAndPlay(endFrame);

 

Please let us know if this is what you want.

 

Regards,

JC

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
Community Beginner ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

Thank you so much this is what I needed

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
Community Expert ,
Jul 17, 2020 Jul 17, 2020

Copy link to clipboard

Copied

LATEST

You're welcome!

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