[SIZE=1]:sen:Hi…I currently have this code(AS3) that starts playing an mp3 when my page loads. It also has a volume slider. Take a look at http://pages.videotron.com/designag/
My question is : can I initialize the volume to a desired level…I want the volume to start at a minimum-medium level. is it possible to set the volume to 3 (1 being very low, 10 being the loudest)?
[/SIZE][SIZE=1]------------------------------------------------------------
[/SIZE][SIZE=1]var loadSnd:URLRequest = new URLRequest(“http://mydomain/myMusic.MP3”);
var thisSnd:Sound = new Sound();
var sndTrans:SoundChannel = new SoundChannel();
var soundVol:SoundTransform = new SoundTransform();
var tracelastSoundTime:Number = 0;
thisSnd.load(loadSnd);
play_btn.visible = false;
stop_btn.addEventListener(MouseEvent.CLICK, stopF);
play_btn.addEventListener(MouseEvent.CLICK, playF);
sndTrans = thisSnd.play();
function playF(eventMouseEvent):void {
sndTrans = thisSnd.play(tracelastSoundTime);
play_btn.visible = false;
stop_btn.visible = true;
}
function stopF(eventMouseEvent):void {
tracelastSoundTime = sndTrans.position;
sndTrans.stop();
stop_btn.visible = false;
play_btn.visible = true;
}
// Code that handles the sound volume
var ratio_volume:Number;
var trackBounds:Rectangle = track_mc.getBounds(track_mc);
var xPos:Number = trackBounds.x;
var yPos:Number = trackBounds.y;
var widthPos:Number = trackBounds.width-track_mc.slider_mc.width;
var heightPos:Number = 0;
var bounds:Rectangle = new Rectangle(xPos,yPos,widthPos,heightPos);
track_mc.slider_mc.x = widthPos;
track_mc.mouseEnabled = false;
track_mc.slider_mc.buttonMode = true;
track_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragSlider);
stage.addEventListener(MouseEvent.MOUSE_UP,stopSlider);
function dragSlider(event:MouseEvent):void {
event.target.startDrag(false,bounds);
addEventListener(Event.ENTER_FRAME,setVolume);
}
function stopSlider(event:MouseEvent):void {
track_mc.slider_mc.stopDrag();
removeEventListener(Event.ENTER_FRAME,setVolume);
}
function setVolume(event:Event):void {
ratio_volume = track_mc.slider_mc.x/widthPos;
soundVol.volume = ratio_volume;
sndTrans.soundTransform = soundVol;
}
Thanks for any help or suggestion.
Pattty
[/SIZE]