PDA

View Full Version : "'undefined' is not a function" error.



I3D
20 Nov 2011, 5:15 PM
Hey Guys

I'm running into a serious error that I can't seem to resolve for some time now. basically I'm starting an audio file to play at the start of the scene, and I'm monitoring to see if the audio file has ended then i'll go to another scene, problem is whenever i do that, i get "'undefined' is not a function" error.


varSceneSound=new buzz.sound(".../something.m4a");
SceneSound.play();
SceneSound.addEventListener('ended', checkEnding,false);
function checkEnding(){

console.log("TEST");
controller.goToNextScene();
}

and if i try to query the object i got a null error, guessing the query object is empty.


varSceneSound=new buzz.sound(".../something.m4a");
SceneSound.play();
var objAudio = document.querySelector("#SceneSound audio");
SceneSound.addEventListener('ended', checkEnding,false);

function checkEnding(){

console.log("TEST");
controller.goToNextScene();
}

any thoughts?

Thanks

I3D
20 Nov 2011, 7:04 PM
ok I was able to minimise the error to the following:


var element = new buzz.sound("http://.../temp.m4a");

element.play();


function checkEnding() {
controller.goToNextScene();
}


element.addEventListener("ended", checkEnding, false);

when i do that, the play function does the trick and plays the audio, how ever adding an event still gives an undefined error! any ideas?

Thanks

arnebech
21 Nov 2011, 10:16 AM
You're getting a Buzz object back, not a regular DOM element probably.

The buzz documentation talks about how to bind/listen on their objects in their documentation.
http://buzz.jaysalvat.com/documentation/sound/#events

So you probably need something like


var sound = new buzz.sound(...)
sound.bind('ended', yourFunctionCallback);