import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.net.URLRequest;
var soundClip:Sound = new Sound(); //declaring variable 'clip'
var soundReq:URLRequest = new URLRequest("test1.mp3");//declaring var 'req' value is 'test1.mp3'
var soundContext:SoundLoaderContext = new SoundLoaderContext(8000, true);//declaring variable 'ctx' value is 8 seconds
var soundControl:SoundChannel = new SoundChannel();//controls the sound (stop/go)
var soundPosition:int = new int (soundControl.position);
var soundLength:int = new int (soundClip.length);
soundClip.load(soundReq, soundContext);//load 'req' with the value of 'ctx' (play at 8 seconds)
soundClip.addEventListener(Event.COMPLETE, onComplete);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onComplete(event:Event):void{
mc_control.btn_play.addEventListener(MouseEvent.CL ICK, playSound);
mc_control.btn_stop.addEventListener(MouseEvent.CL ICK, stopSound);
}
function playSound(event:MouseEvent):void{
soundControl.stop();
soundControl = soundClip.play(soundPosition);
mc_control.swapChildren(mc_control.btn_play, mc_control.btn_stop);
}
function stopSound(event:MouseEvent):void{
soundPosition = soundControl.position;
soundControl.stop();
mc_control.swapChildren(mc_control.btn_play, mc_control.btn_stop);
}
function onEnterFrame(ev:Event):void{
trace(soundControl.position/soundClip.length*100)
mc_position.x = 101+(soundControl.position/soundClip.length*294);//% of song played along a bar 294px long
mc_loaded.width = 297/(soundClip.bytesLoaded/soundClip.bytesTotal);//% of song loaded along a bar 297px long
}