Calling a scene to change using JavaScript

Ok I need to call a scene to be displayed and need to do it from a iframe. this is what I thought the scrip should look like.

window.parent.hypeDocument.showSceneNamed(‘Consumption’, 2, 1.1)

Consumption is the scene name but I get a error function not found. Can someone please help?

Thanks,
Jon

Hi Jon

In your head.html include this:

<script>
    	
function myCallback(hypeDocument, element, event) {
    	
  window.myhypedocument = hypeDocument;
    	
}    	
  
if("HYPE_eventListeners" in window === false) {    	
    window.HYPE_eventListeners = Array();
}

window.HYPE_eventListeners.push({"type":"HypeDocumentLoad", "callback":myCallback});
</script>

Then in your html widget (iframe) something like this:

<div onclick="window.parent.myhypedocument.showSceneNamed('Consumption');">
NextScene
</div>

Edit* By the way this was curtesy of @h_classen in another post.

Hope this helps!

D

I get this error.

undefined is not an object (evaluating ‘window.parent.myhypedocument.showSceneNamed’)

Hi Jon,

can you post you Project so we can see what you are doing. This will make it easier to spot the issue.

P.S.

I change your Title. I had been ignoring this post because you had Java in the title. Which is something completely different to JavaScript.

i found the error. “top.myhypedocument.showSceneName(‘Consumption’,2,1.2)” worked. I have to load data into the widgets after the webpage is loaded and in the widget is a iframe. to find the main page containing the hype controls i have to use top. instead of window.parent because the parent is the iframe widget and not the main window. Thanks for the help and the pointer to the code to put in the Header of the hype doc. That lead me to the function witch I was able to find with a debugger displaying the page.

Hello,
i use “this.myhypedocument. …” instead of “window.parent.myhypedocument. …” to address a (this) document in a iFrame. Is this correct?