sceneNames() API

Hello!

I have created many website-like projects in Tumult Hype, and to learn Saola Animate, I was trying to replicate most of my projects. So, I stembled upon this. In Hype, I could run a JS fucntion onSceneLoad to set the URL in address bar. It would allow me to link to a specific scene externally as each scene now had its own URL and also, it could allow users to use the brower navigation (Back, Forward, Refresh). Thus, all I had to do was set distinct Scene Names without spaces and I had got a complete website-like project. This is the script:

var checkHash = function()
	{
		var hash = window.location.hash.substring(1);
		for(var i = 0; i < hypeDocument.sceneNames().length; i++)
			{
 				if(hypeDocument.sceneNames()[i] == hash)
					{
 						hypeDocument.showSceneNamed(hash);
 						break;
 					}
 			}
 	};
if (window.loadedHashLocation != true)
	{
		window.loadedHashLocation = true; 
 		checkHash(); 
 		window.onhashchange = checkHash; 
 	}
window.location.hash = "#" + hypeDocument.currentSceneName();
}

Well, it seems like it can be reproduced in Saola Animate too, but, I got stuck at line 3: hypeDocument.sceneNames(). The hypeDocument.sceneNames() returns the names of all the scenes in the document as an array. I couldn’t find a similar API in Saola. I found the getSceneCount one. Other than that, I guess, all other Hype APIs from the above code are available in Saola.

Now, I read on the forum that I can set a Start Scene parameter in the document initialization code in the HTML5 output, but, it’s not really practical. Firstly, I’d have to create an individual page for each scene. Secondly, I won’t be able to use scene transitions. Thirdly and probably lastly, I’d have to hard-code links in my document, as opposed to switching scenes, so, it will create problems in previewing.

I’d thus like to request Atomi team to consider including this API to their already long list in a future release.

You don’t need line three - it’s simply part of a loop to check if the scene exists. If you call doc.showScene(hash), Saola will return false if not found or show the scene if it exists.

2 Likes

Thank you for the info. So, accoringly, I modified the code:

var checkHash = function()
    {
        var hash = window.location.hash.substring(1);
        doc.showScene(hash);
    };
if (window.loadedHashLocation != true)
    {
        window.loadedHashLocation = true;
        checkHash();
        window.onhashchange = checkHash;
    }
window.location.hash = "#" + doc.getScene();
}

In a test document, I created 2 scenes (Scene1 and Scene2). I ran the function on activation of both scenes. However, when I choose to preview the project, my document automatically loads Scene2 and the URL is set to #[object%20Object] instead of #Scene2. Also, when I enter #Scene1 in the URL, nothing happens. Am I missing something?

UPDATE: The Scene2 was loading because of AutoAdvance enabled. Now, entering the URL works fine. However, the URL is not showing Scene Name, instead, it shows [object%20Object].

Is getScene() the correct function to get the Scene Name?

Hi Hrishikesh,

doc.getScene() return current scene object. You can use doc.getScene().name for the scene name.

Regards

1 Like

Great! That’s it! Thank you both!!

So, if anyone wants to link to the scenes externally, they can run the following function on scene activate of each scne:

var checkHash = function()
    {
        var hash = window.location.hash.substring(1);
        doc.showScene(hash);
    };
if (window.loadedHashLocation != true)
    {
        window.loadedHashLocation = true;
        checkHash();
        window.onhashchange = checkHash;
    }
window.location.hash = "#" + doc.getScene().name;