Switch a scene from the index.html file

94 views
Skip to first unread message

Joost

unread,
Jul 30, 2021, 3:06:30 PM7/30/21
to marzipano
Hi,

Just wondering. Is it somehow possible to add a javascript in the index.html file that switches to another scene?

I mean: How do I call the switchScene(scene) function in the index.js file from the index.html file? Is that somehow possible?

What I tried and didn't work, i added the following to the end of the index.html file, just before the </body> tag;

<script>
    switchScene("testscene");    ---> switchScene not defined
    Marzipano.switchScene("testscene");    ---> switchScene is not a function
    
</script>

Any advise?

thanks
Joost

Carlos Eduardo G. Carvalho (Cartola)

unread,
Aug 7, 2021, 12:24:36 PM8/7/21
to marzipano
I've tried A LOT here, without success too.

Tried to associate the action to events, putting at the beginning, at the end, many variations, all failed. Just didn't get those errors at the console. :( Well, I'm a javascript newbie.

--
You received this message because you are subscribed to the Google Groups "marzipano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marzipano+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/marzipano/6431f06f-85eb-40cf-b06f-c9808b1b485an%40googlegroups.com.

Joost

unread,
Aug 9, 2021, 4:21:31 AM8/9/21
to marzipano
Hi,

So I found one possibility to switch to another scene from my index.html. Still, it feels like an un-perfect method to do this.

How I did it, example;
I added an ID to all the defined scenes 
      <a href="javascript:void(0)" class="scene" data-id="5-room1_main_dooropen" id="opendoor">
        <li class="text">room1_main_dooropen</li>
      </a>
    
Then I added a simulation of a click on the link in javascript, later in the code;
  $('#opendoor')[0].click();

So when I simulate the click it switches to the "opendoor" scene. 
Still wondering if there are any other ways to reach the "switchScene" function from the index.html file.
(will continue looking for other ways)

greetings
Joost

Op za 7 aug. 2021 om 18:24 schreef Carlos Eduardo G. Carvalho (Cartola) <cart...@gmail.com>:

arulchris

unread,
Aug 9, 2021, 5:10:25 AM8/9/21
to marzipano
Hi,

Its about the scope of the function. As the entire code in index.js file resides inside a self-executing function, the function switchScene() wont be available outside its scope.
You can make the code available outside / public by removing self-executing function in the index.js file.
May look like this,
'use strict';
(function() {  //<- comment or remove this line
...Code..
})(); //<- comment or remove this line

Or

You can just assign the switchScene() and findSceneById() to the window object to make it available on the index.html file.
Like this:
window.switchScene = function switchScene(scene) {
....
}
window.findSceneById = function findSceneById(id) {
....
}

These methods are not a proper way of development. Im just sharing for understanding. 

Hope it helps !

Best
Chris
Reply all
Reply to author
Forward
0 new messages