I have a very weird scenario in which there is a HTML widget in my scene with a manually added button. I need to be able to hide an element in the scene (a rectangle in this case) by clicking the button inside the widget. However, I need to be able to do it with an event listener attached to that button (see buttons inner html)
Syntax is a little complicated so I’m trying to understand what is going on. When you declared the hypeDoc variable, what does the “Object.keys” refer to and why is the ‘parent.HYPE.documents’ repeated?
HYPE.documents is a javascript object where the keys are the names of the document and the values are the document object itself.
The inner Object.keys(parent.HYPE.documents)[0] call is basically saying "let's get the first key," then it is using it in the documents object to get the value of this first key. Extracted out with names, it would be more like:
var hypeDocNames = Object.keys(parent.HYPE.documents);
var firstHypeDocName = hypeDocNames[0];
var hypeDoc = parent.HYPE.documents[firstHypeDocName];
Another technique would be to use the Object.values() method just to get the values, and use the first one:
var hypeDoc = Object.values(parent.HYPE.documents)[0];
(In both of these methods, it is really assuming there's only a single hype document on the page. If this isn't the case, you'd need to know the name itself and look it up that way.)