Hi there,
In the attached Hype document, the main timeline is immediately paused and has to wait for an external JavaScript function to trigger it to continue.
I followed the documentation, and it works as long as the external function is called BEFORE the HypeSceneLoad event.
In this case however, the external JavaScript function may take some time to get called, in which case it doesn't work anymore, probably because the HypeSceneLoad event has already passed (you can adjust myTimeOut to 1000ms in order to simulate the delay).
Can you please tell me how to launch the animation after Hype has loaded?
Many thanks in advance. WaitForTriggerFunction.hype.zip (27.3 KB)
<script>
function ContinueMainTimeline(hypeDocument, element, event) {
hypeDocument.continueTimelineNamed('Main Timeline', hypeDocument.kDirectionForward, false);
}
function ExternalTrigger() {
console.log('Trigger called');
if (("HYPE_eventListeners" in window) === false) {
console.log('Hype document not yet loaded');
window.HYPE_eventListeners = Array();
}
window.HYPE_eventListeners.push({ "type": "HypeSceneLoad", "callback": ContinueMainTimeline });
}
var myTimeOut = setTimeout(ExternalTrigger, 10);
</script>
I cooked a quick workaround which does not rely on Hype events:
The external trigger function just sets a flag to true, which is checked every 30th of a second by a looping "Wait" timeline launched at the start (see attached Hype doc).
It's not very clean but it does the job.
Feel free to show me a better way to do it.
Thanks and cheers!
The only effect you want to achieve is that the timeline starts after a time X, right? Or am I misunderstanding you? So why not simply call the following script on sceneLoad? No script in the head necessary...
In your head, we can alias the Hype function to the windows scope.
This will also save you hard coding the hype documents name etc.. with other approaches.
<script>
function hypeDocLoadCallback(hypeDocument, element, event) {
console.log("Setting up window scoped Alias function")
window.hypFunc = function(){
hypeDocument.functions().WaitForTrigger(hypeDocument, element, event)
}
}
if("HYPE_eventListeners" in window === false) {
window.HYPE_eventListeners = Array();
}
window.HYPE_eventListeners.push({"type":"HypeDocumentLoad", "callback":hypeDocLoadCallback});
setTimeout(() => {
console.log("Simulate external trigger calling Alias function")
window.hypFunc()
}, "1000");
</script>