Accessing FUNCTIONS of iframe/parent from parent/iframe

This is my hype project structure:

iframe1 contains a hype generated animation. iframe2 contains an editor. In my special case, I preferred iframe over symbols.

I accessed the editor of iframe2 from parent. And also the editor of iframe2 from iframe1 through parent:

parent -> iframe2
hypeDocument.getElementById('iframe2').children[0].contentWindow.editor

iframe1 -> parent -> iframe2
window.parent.document.getElementById('iframe2').children[0].contentWindow.editor

My question is how to run the animation of iframe1 from the parent?

Update: I got the document object of iframe1 from the parent using

hypeDocument.getElementById('iframe1').children[0].contentDocument

But this is not a hypeDocument object which can run the animation. Can someone tell me how to get the hypeDocument from the contentDocument?

Given a window object, you can get at a hypeDocument via window.HYPE.documents["documentName"].

That said, it may be easier/more robust to use postMessage() to communicate between iframes with a receiver setup with an on scene load handler (there are some other forum posts showing how to use this).

1 Like

Thank you, Jonathan!