If you are going to define elements in HTML and then access them from javascript you need to ensure that the document is finished loading before you attempt to access them. I think it is sufficient to move any uses of document.getElementById
to the setup()
function (this assumes the setup is only called after document
raises the onreadystatechange
event and has a readyState
value of 'complete'
).
I was able to make your sketch work by adding the following line to your setup function:
playButton = document.getElementById("play-button");