function SoundEffect(src, loadedCallback, callbackContext) { this.loadedCallback = loadedCallback; this.callbackContext = callbackContext; this.loaded = false; this.audio = new Audio(); this.audio.owner = this; this.audio.observe("canplaythrough", function(event) { this.owner.loaded = true; if (this.owner.loadedCallback != null) { this.owner.loadedCallback(this, this.owner.callbackContext); } }); this.audio.observe("error", function(event) { console.log("SoundEffect error! " + event); }); this.audio.observe("abort", function(event) { console.log("SoundEffect abort! " + event); }); this.audio.src = src; this.audio.load(); } SoundEffect.prototype.play = function() { this.audio.pause(); this.audio.currentTime = 0; this.audio.play(); }