How to Call One JavaScript Function in the Resource Manger, From Within Another?

I have created several JavaScript functions in the resource library.

I would like to call one function [in this case displayScore()] from within another JavaScript function, [in this case initializeWidget()]. Can this be done? If so, how?

All attempts have thus far resulted in this type of failure:

displayScore(); produces the error:
Error in initializeWidget: TypeError: hypeDocument is undefined

or

hypeDocument.functions().displayScore(); produces the error:
Error in initializeWidget: ReferenceError: displayScore is not defined

hypeDocument.functions().displayScore(hypeDocument, element, event); should work :slight_smile:

4 Likes

Worked like a charm! :blush:
Well, I guess you can see I'm just learning this stuff. Thanks for the help!

I keep forgetting about that. Wish it was in the documentation.

When testing this I wondered how using this method you could pass a variable on.

And realised you could change one of the standard hypeDocument, element, event ones to an array.

So in the first js code you would have something like:

hypeDocument.functions().js2(hypeDocument, [element,"hello"], event);

And in the js2() functions code you would have someone like:

var element_ = element[0];
var fooString = element[1];
3 Likes

haha, that’s so obviously! never mentioned this! thx :slight_smile:

Thanks for the extra información!

I think
hypeDocument.triggerCustomBehaviorNamed(‘customBehaviorName’)
is another way to trigger any javascript, without having to set unique element id’s.

1 Like

Thanks for providing more info! Although I already resolved the issue I’m sure it may be helpful in the future.