1
0
Fork 0

Bugfixed, tested, and added example

This commit is contained in:
Starbeamrainbowlabs 2015-02-19 20:17:16 +00:00
parent 565c587b34
commit 6777e14664
1 changed files with 5 additions and 4 deletions

View File

@ -1,16 +1,17 @@
function SoundBox() {
this.sounds = {};
this.sound_callbacks = {};
this.add_sound = function(sound_name, path) {
this.load = function(sound_name, path) {
this.sounds[sound_name] = new Audio(path);
// reset the sound ready for the next playing
this.sounds[sound_name].addEventListener("ended", function(event) {
this.sounds[sound_name].addEventListener("ended", (function(event) {
event.target.currentTime = 0;
if(typeof this.sound_callbacks[sound_name] == "function")
{
this.sound_callbacks[sound_name](sound_name);
delete this.sound_callbacks[sound_name];
}
});
}).bind(this));
};
this.remove = function(sound_name) {
@ -30,6 +31,6 @@ function SoundBox() {
if(typeof callback == "function")
this.sound_callbacks[sound_name] = callback;
this..sounds[sound_name].play();
this.sounds[sound_name].play();
};
}