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.
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 /
...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.
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
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
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
Copy link to clipboard
Copied
Thank you so much this is what I needed
Copy link to clipboard
Copied
You're welcome!