I’d like to run a javascript function ONLY after all of the scenes have been viewed.
I’ve looked at several threads about how to get scene info etc. and I’m guessing there is a way to do this using Hype Extension. Is there a way to use “sceneInfo.sceneCount” and based on the total number of scenes have the function run when the total is reached?
I just can’t figure it out.
I’ve attached a demo file. View Scenes Example.hype.zip (39.0 KB)
Have not looked at your example - short on time here - but here is one strategy which You have already touched the shores of - use an array. Info about using arrays here.
Get the total count of all scenes in the Hype document.
Then on each “Scene Load” check the scene name with the names in the array.
If the scene name is not in the array add it to the array ( “push()” ).
Check the array length if the array length = the sceneCount You are home Baby!
Again all the references to using arrays mentioned in the paragraph just above are covered in the “here” link in the first paragraph.
===============================
Example of checking for a value in an array - doing this on the fly so consider this general concept:
We have a variable “sceneName” with the current scene name already placed into it (e.g. “Part 3”)
We have our array “sceneChecker” with other scene names placed into it (we’ve already visited those scenes). This array currently contains [“Intro”, “Part 1”, “Part 2”, “Epilogue”]
“On Scene Load”
<script>
function checkSceneName() {
var n = sceneChecker.indexOf(sceneName);
if (n == -1) {sceneChecker.push(sceneName);}
}
</script>
"indexOf" returns “-1” if the item is not found in the string (i.e. the array), so we will add “Scene 3” to the array (i.e. the “push” method).
Then using the prepare for display scene action we run this script which gets the current scene name, checks if it is in the hypeDocument.customData.allScene array and removes it if it is.
Once the hypeDocument.customData.allScene count is equal to 0 we can run the other javascript function.
hypeDocument.customData.allScene.map(myFunction)
function myFunction(nam,index) {
if (hypeDocument.currentSceneName() == nam && hypeDocument.customData.allScene.length != 0){
hypeDocument.customData.allScene.splice(index, 1)
}
if (hypeDocument.customData.allScene.length == 0){
hypeDocument.functions().someFunction()
}
}
The above can be jiggled as you want it to meet your needs.
It can also all be done in the head with another head script to run the checker on prepare for display
etc.