function loadSound(sound:String, vol:Number, loop:Boolean):Object { var d:Number = _root.getNextHighestDepth(); var emptyMC:MovieClip = _root.createEmptyMovieClip("empty" + d, d); // multifunctional container var SoundObj:Object = new Object(); SoundObj.sound = new Sound(emptyMC); SoundObj.sound.attachSound(sound); SoundObj.sound.setVolume(vol); SoundObj.sound.onSoundComplete = function() { SoundObj.isPlaying = false; }; SoundObj.isLoop = loop; SoundObj.isPlaying = false; // only start playing when sound is not already playingSoundObj.softStart = function(Play:Boolean) { if (Play) { if (!this.isPlaying) this.sound.start(0, this.isLoop ? 999 : 0); } else { if (this.isPlaying) this.sound.stop(); } this.isPlaying = Play;} // restart playing no matter whatSoundObj.hardStart = function(Play:Boolean) { this.sound.stop(); this.isPlaying = false; this.softStart(Play);} return SoundObj;}