To expand on @drewbullen's answer a bit, Hype event handlers are functions, so when you do something like:
function chooseA(hypeDocument, element, event) {
var a = 1;
var b = 0;
var c = 0;
// ... and so on
}
Because you declared the variables with a var
keyword, they are scoped to the function, and don't live outside that particular function. So you cannot access them from a different function (like a different event handler). This isn't particular to scenes; two event handlers that run in the same scene don't have access to them either. Further, once the function is done running, the variables are cleaned up -- so they always start fresh when the function is called.
Therefore when you have another function like:
function whichChoice(hypeDocument, element, event) {
if (a = 1) {
hypeDocument.getElementById("choice").innerHTML = "Site 1";
} else if (b = 1) {
The a
that you are referencing here has no knowledge of the a
defined in another function, especially since it doesn't even exist at the time you're calling this.
"naked" variable access like this goes to the global scope. Since your declarations before were local to the function, you won't have them defined.
Now what you could have done is remove the var
keyword in the chooseA()
function, and then they would also be on the global scope and this would theoretically work.
However, while it might work, it is a particularly bad idea for several reasons to do it this way. The global scope means anything on the .html page can use those variable names. This could be other Hype documents, including your own. Or it could be other scripts that you've included. In particular, since these are single letter variable names there's a good chance someone other script might be accidentally colliding with them.
Instead, @drewbullen's suggestions are spot-on, you can store things into the hypeDocument.customData
storage, which is intended exactly to solve your problem.
Setting the variables would look like:
function chooseA(hypeDocument, element, event) {
hypeDocument.customData.a = 1;
hypeDocument.customData.b = 0;
hypeDocument.customData.c = 0;
// ... and so on
}
And testing the variables would look like:
function whichChoice(hypeDocument, element, event) {
if (hypeDocument.customData.a == 1) {
hypeDocument.getElementById("choice").innerHTML = "Site 1";
} else if (hypeDocument.customData.b == 1) {
One very important note is that a single =
sign is for variable assignment in JavaScript. A ==
is required for equality testing. So note that I changed those in the example, since your code will definitely do the wrong thing with a single equal sign.
Scoping is a core JavaScript concepts to learn, so I'd recommend reviewing some other online docs to reinforce how it all works
.