Advance though timeline in increments

(Lee) #1

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)

(Greg) #2

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)

(Lee) #3

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?

(Greg) #4

Searching the forum for “Loop Timeline” comes up with a lot of good info, for instance…

with loop on timeline… (24.9 KB)

(Lee) #5

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

(Greg) #6

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)