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

(Andrew) #1

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


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

Run script from another script
(Hans-Gerd Claßen) #2

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

(Andrew) #3

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

(Mark Hunte) #4

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];

(Hans-Gerd Claßen) #5

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

(Andrew) #6

Thanks for the extra información!

(Thomas Lundin) #7

I think
is another way to trigger any javascript, without having to set unique element id’s.

(Andrew) #8

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