Set number of loops

I know you know the answer to that…

symbolInstance_.pauseTimelineNamed('loop')

symbolInstance_.startTimelineNamed('col', hypeDocument.kDirectionForward);
`
1 Like

Kinda ?

if (window[element.id].counter > 15){
	symbolInstance_.pauseTimelineNamed('loop')
	symbolInstance_.startTimelineNamed('col', hypeDocument.kDirectionForward);
2 Likes

Thats it.

:+1:

2 Likes

If you want to avoid code, you can also just have a second timeline that triggers stuff on the 15s frame with a an timeline actions.

1 Like

Yes, true I was aware of that, but this one needs the above the solution. Without going too much into detail, the loop is basically for a propeller of a Drone Mavic 2 Zoom/Pro consisting of just one symbol propeller duplicated for 4x times for 4x sides spinning at rate .1 - .2 seconds in y coordinate giving it a sense of that fast movement? Anyhow, Safari gave me a warning because that propeller animation being in a constant state of loop thereby almost ‘choking the browser’?

Update:
Im toying with different ideas that may or not need the above.

I ended up not going with the above and made a decision to stop the animation for the propeller at a specific point in time by dropping an action in different timelines where it needed to be stopped where it was needed and hide the spinning drone by just using this

 var allSymbolInstances = hypeDocument.getSymbolInstancesByName('Spinner');
 for (var i = 0; i < allSymbolInstances.length; i++) {
 	var symbolInstance = allSymbolInstances[i];
 	symbolInstance.pauseTimelineNamed('Main Timeline', hypeDocument.kDirectionForward);
 }	

heres the result

1 Like

This is exactly what I was after! Thank you so much! :grin:

1 Like

Was this ever implemented in any updates since March 2015?
Thanks

Specified loop count is not a feature presently; the code above is still the best way to accomplish this.

2 Likes

Here’s a simplified version of a ‘loop only X times’ function that requires a single timeline action:

if (window.loopCount == null) {
	window.loopCount = 0;
}


// as long as loopCount is less than 3, do this:
if (window.loopCount < 3) {

	// add 1 to loopCount. 
	window.loopCount++;
	
	// this can be removed, but it writes 'loopCount' into your Hype document:
	document.getElementById("loopcount").innerHTML = loopCount;
	
	// since we count one 'loop' after passing the timeline action, it will 
	// actually play four times total, since the loopCount will be greater than 3 on its
	// fourth 'play'
	hypeDocument.startTimelineNamed('Main Timeline', hypeDocument.kDirectionForward);
}


if (window.loopCount == 3) {
hypeDocument.pauseTimelineNamed('Main Timeline');
}

loopCount.zip (21.1 KB)

2 Likes

Here is a slightly modified version of Daniels code that works on any timeline and stores the counts in a local context rather than in window. Still room for improvement.

	var key = element.id+'_loops';
	
	if (hypeDocument.customData[key] == null) {
		hypeDocument.customData[key] = 0;
	}

	// as long as loopCount is less than 3, do this:
	if (hypeDocument.customData[key] < 3) {

		// add 1 to loopCount. 
		hypeDocument.customData[key]++;
	
		// this can be removed, but it writes 'loopCount' into your Hype document:
		document.getElementById("loopcount").innerHTML = hypeDocument.customData[key];
	
		// since we count one 'loop' after passing the timeline action, it will 
		// actually play four times total, since the loopCount will be greater than 3 on its
		// fourth 'play'
		hypeDocument.startTimelineNamed(event.timelineName, hypeDocument.kDirectionForward);
	}


	if (hypeDocument.customData[key] == 3) {
		hypeDocument.pauseTimelineNamed(event.timelineName);
	}

3 Likes