Hype Javascript Function Control


#1

Hello everyone,

I’m curious to know if someone may have any ideas on how to trigger a clearInterval on a scene unload.

The Javascript code I am using makes dots on the page go from invisible to visible. I have a setInterval checking a number every 100 milliseconds. When the scene unloads, I would like to run a function that triggers a clearInterval.

Below is the code I am currently using:

    var mph = setInterval(function(){ check() }, 100); function check() {var speedo = parseInt(document.getElementById("speed").innerHTML, 10); console.log(speedo);if(speedo <= 0){hypeDocument.getElementById("dot1").style.opacity = "1";} if(speedo >= 1){hypeDocument.getElementById("dot2").style.opacity = "1";} else {hypeDocument.getElementById("dot2").style.opacity = "0”;}

Any ideas?

Thanks!


(Hans-Gerd Claßen) #2

make your mph global. explicit with window.mph or just mph. this way you should be able to access it …


#3

Hi Hans! Thanks for the rapid reply!

I am a total beginner in Javascript, but am getting better everyday! How can I go about making the mph variable global?

Thanks again!!


(Hans-Gerd Claßen) #4
mph = ...

or

window.mph = ...

google or search this forum for the differences …
as far as i remember mraddy did a good explanation…


#5

You are a saint! Thank you so much!

I have to say, this is easily the best online community I’ve been apart of. Everyone here is so nice and helpful, not condescending and rude like on stack overflow.

Thank you again!!


(Hans-Gerd Claßen) #6

well, stackoverflow is the best source for solutions around webtopics …