Need to control sound with a play button, stop button, volume up and volume down.
Use SoundChannel and SoundTransform.
var req:URLRequest=new URLRequest("sound.mp3");
var mySound:Sound=new Sound;
var myController:SoundChannel;
var myVolumeControl:SoundTransform;
mySound.load(req);
mySound.addEventListener(Event.COMPLETE, mySoundLoaded);
function mySoundLoaded(event:Event):void {
myController=mySound.play();
myController.stop();
myVolumeControl=myController.soundTransform;
play_btn.addEventListener(MouseEvent.CLICK, playMySound);
stop_btn.addEventListener(MouseEvent.CLICK, stopMySound);
upVolume_btn.addEventListener(MouseEvent.CLICK, volumeUp);
downVolume_btn.addEventListener(MouseEvent.CLICK, volumeDown);
}
function playMySound(event:MouseEvent):void {
myController=mySound.play();
}
function stopMySound(event:MouseEvent):void {
myController.stop();
}
function volumeUp(event:MouseEvent):void {
myVolumeControl.volume+=.1;
if (myVolumeControl.volume>1) {
myVolumeControl.volume=1;
}
myController.soundTransform=myVolumeControl;
}
function volumeDown(event:MouseEvent):void {
myVolumeControl.volume-=.1;
if (myVolumeControl.volume<0) {
myVolumeControl.volume=0;
}
myController.soundTransform=myVolumeControl;
}
View source in the attached file.
Thank you for reading.
+