Revox Posted January 18, 2016 Share Posted January 18, 2016 I'm loading and playing an AudioSprite with JSON which works fine. But when I try to listen for the end of the sound I get a type Error. game.load.audiosprite('sfx', ["snd/animalSounds.mp3", "snd/animalSounds.ogg"], "snd/animalSounds.json",true); fx = game.add.audioSprite('sfx'); fx.allowMultiple = true; fx.play("intro"); fx.onStop.add(soundStopped ,this); onloadphaser.js:70687TypeError: undefined is not an object (evaluating 'fx.onStop.add') Can this be done using .onStop? Link to comment Share on other sites More sharing options...
drhayes Posted January 19, 2016 Share Posted January 19, 2016 What's the definition of your soundStopped method? Is fx global? Link to comment Share on other sites More sharing options...
Revox Posted January 19, 2016 Author Share Posted January 19, 2016 fx is global, that was my first thought. but I was successfully logging out fx on the line before the onStop listener. That made me think that I needed to add the onStop to a sound rather than the audioSprite. Then found onMarkerComplete andI was able to get this to work. game.load.audiosprite('sfx', ["snd/animalSounds.mp3", "snd/animalSounds.ogg"], "snd/animalSounds.json",true); fx = game.add.audioSprite('sfx'); fx.allowMultiple = true; fx.play("intro"); console.log(fx); fx.sounds.intro.onMarkerComplete.add(function(key) {console.log(" Done Playing “+key); }) It works. I’m not sure if this is the intended implementation. Link to comment Share on other sites More sharing options...
Recommended Posts