I've been working on the next Hype video and I realize that I probably shouldn't be teaching people to use window.data as that's not considered ideal programming. So, what's the alternative? That's when I looked at hypeDocument.customData
.
The reason I use window.data is the reason not to use it — any JavaScript code can access it.
At first I was like, whatever, name your variables better. I haven't had a problem with collisions. Then again, I wasn't trying to put two quizzes on the same page. So, I tested it out. Yup, that's a problem. If both quizzes are using window.data
then there's going to be a problem.
However, I wasn't sure if hypeDocument.customData
would solve the problem. Wouldn't that have the same issue? So, I tested it. Apparently not!
Those are two Hype documents. On startup, they both write a hypeDocument.customData.color
value. One writes "red" and the other writes "blue". When the button is pressed, the name of the button is changed to the hypeDocument.customData.color
value.
Surprisingly, this worked. And just to be sure, I tested it with window.color
— that didn't work.
Interesting.
hypeDocument.customData
is unique to the Hype document.
Custom Data Test.zip (93.8 KB)
Side Note: Perhaps the styling for code elements on this site should be changed. It's not easy to see the highlighting for code elements.