Advance though timeline in increments

How can I make the following code work in the attached hype document to allow the user to advance though a timeline from start to finish and then loop back around infinite times?

var currentTime = hypeDocument.currentTimeInTimelineNamed('Main Timeline');
hypeDocument.goToTimeInTimelineNamed((currentTime + 0.5), 'Main Timeline');

the hype document attached contains a no code version that works as planned, and a version where multiple buttons have been replaced with a single one which has a javascript function applied on click.

advance in increments .zip (33.1 KB)

Try this script…

var currentTime = hypeDocument.currentTimeInTimelineNamed('Main Timeline');

// console.log(x); // Note that Javascript uses a different format for the time in the timeline 

hypeDocument.goToTimeInTimelineNamed(currentTime + 0.5, 'currentTime');

The Main TimeLine will continue after each click unless you add pauses in your script. (13.2 KB)


thanks, this is working great. I added a timeline action at the end of the animation assuming it would loop back to the start, but it stays put - how can I make the animation loop so the button can be clicked infinite times?

Searching the forum for ‚ÄúLoop Timeline‚ÄĚ comes up with a lot of good info, for instance‚Ķ

with loop on timeline… (24.9 KB)

This works until I introduce pause timeline actions, then it stops looping (25.9 KB)

Maybe you do not need javascript for this. You can use Hype’s actions to pause and continue with the loop in place

Sample without javascript (25.0 KB)