// Author: Robert Lie (Mobilefish.com) // More information, see: https://www.mobilefish.com/developer/flash/flash_quickguide_actionscript_3_examples.html var soundReq:URLRequest; var sound:Sound = new Sound(); var soundControl:SoundChannel = new SoundChannel(); var resumeTime:Number = 0; var keyStr:String; var valueStr:String; var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters; for (keyStr in paramObj) { valueStr = String(paramObj[keyStr]); if(keyStr == "soundfile") { soundReq = new URLRequest(valueStr); sound.load(soundReq); sound.addEventListener(Event.COMPLETE, onComplete); } } function onComplete(event:Event):void { play_btn.addEventListener(MouseEvent.CLICK, playSound); stop_btn.addEventListener(MouseEvent.CLICK, stopSound); } function playSound(event:MouseEvent):void { soundControl = sound.play(resumeTime); pause_btn.visible = true; pause_btn.addEventListener(MouseEvent.CLICK, pauseSound); play_btn.visible = false; play_btn.removeEventListener(MouseEvent.CLICK, playSound); } function pauseSound(event:MouseEvent):void { resumeTime = soundControl.position; soundControl.stop(); play_btn.visible = true; play_btn.addEventListener(MouseEvent.CLICK, playSound); pause_btn.visible = false; pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound); } function stopSound(event:MouseEvent):void { resumeTime=0; soundControl.stop(); play_btn.visible = true; play_btn.addEventListener(MouseEvent.CLICK, playSound); pause_btn.visible = false; pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound); } pause_btn.visible = false;