Javascript Audio not working


(Andrew) #1

As per the link, below,

var myAudio = document.getElementById("awesome"); 
myAudio.play();

HTML is as below:

But I keep getting this error:

TypeError: null is not an object (evaluating ‘myAudio.play’)

Not sure why ?


Best way to create interactive text
(Andrew) #2

It was because I put it into a HTML Widget. Needs to be a standard shape ?


#3

When placing an audio element like that into an iframe, it becomes insulated from the parent. So, when you try to play the ‘awesome’ element ID, it looks in the same level (your Hype document) but cannot see that there is an element within the HTML Widget. The HTML widget is essentially an iframe, and it is embedded within your Hype document.

Yes – putting the audio element at the same level (embedded within rectangle) will do the trick.