HTML Widget function not responding

Hi,

I have a HTML Widget with this embedded inner HTML :

<script language="javascript">
	function messageReceived() {alert ( "Received the message!" );}
</script>

if I have a Hype function (called ‘sendMessage’) calling messageReceived();

I get this error :

Error in sendMessage: ReferenceError: Can't find variable: messageReceived

I really can’t figure why (see small Hype file in attachement)

Thank you for your help.

Cheers.

SendMessage.hype.zip (10.4 KB)

Hi @teo1310

2 things …

• 1. In order to access the HTML widget (iframe) you have to add some more code.

window.widget = document.getElementById('toto').firstChild; /// gets the iframe

widget.contentWindow.messageReceived(); // enables connection to the function

• 2. You cannot call your sendMessage() function from scene load directly or from the first keyframe in your timeline. You have to move the keyframe over 1 or 2 or 3 frames or set a timeout in the scene load and then call it.

Many thanks, it works perfectly.