How to call hype js function from external HTML

Hi, I am trying to call MyFunction defined in Hype document. Please can you provide simple html that calls MyFunction?

I have tried:
hypeDocument.functions().MyFunction(hypeDocument, element, event);

but get:

Uncaught ReferenceError: hypeDocument is not defined(anonymous function)
@ 70e34:91f.Callbacks.n @ jquery.min.js:2f.Callbacks.o.fireWith @ jquery.min.js:2e.extend.ready @ jquery.min.js:2c.addEventListener.B @ jquery.min.js:2

When running a function outside of the Hype document, you’ll need to include the document’s name (chosen when you export as HTML). If your document were named DocumentName, you would use this function:

HYPE.documents['DocumentName'].functions().MyFunction(HYPE.documents['DocumentName'],'foo',event);

(Edit: February 8, 2016 to fix the above function)

1 Like

You had also asked how to restart an animation from outside of a Hype document. This function starts a scene instantly:

HYPE.documents['DocumentName'].showSceneNamed('MyScene',HYPE.documents['DocumentName'].kSceneTransitionInstant);

Daniel, thank you very much! It works now…

Hello Hype / JavaScript gurus!

I have made a simple ‘find a word’ game utilising the canvas element:
https://content.une.edu.au/2020/find-a-word.html

When a word is found, I am hoping to trigger a hype function that will cross the word off a word list and play a “word found!” animation of some kind. I found this post where Daniel gives some code for calling Hype functions from outside of the Hype object:


HYPE.documents[‘DocumentName’].functions().MyFunction(HYPE.documents[‘DocumentName’],‘foo’,event);

… hoping someone might be kind enough to explain what this code is achieving? Is the function that is being called one that has a name “MyFunction(e, foo)” - i.e passing event object and “foo” is a function parameter?

If you have an Hype function name MyFunction .i.e

HYPE.documents[‘DocumentName’].functions().MyFunction(HYPE.documents[‘DocumentName’],‘foo’,event);

Will Tell the Hype Hype document named DocumentName to run its function named MyFunction

We are passing on arguments to the MyFunction function

The arguments will need to be passed or you will get an error.

The normal arguments are (hypeDocument, element, event)

So in this case we are using

HYPE.documents[‘DocumentName’] in place of hypeDocument
‘foo’ in place of element

(Note here foo is a string so any reference to element in the hype document’s function will only see a string not an actual element. )

and

event for event

(Note here Event is a var so it would need to be declared first )

3 Likes

Thank you Mark, much appreciated!