A continuation from the music player tutorial we introduce the Sound Transform class to handle sound volume control. The buttons are created live on stage.
CLICK HERE FOR A COMPLETE CARTOON SMART SOUND AND MUSIC TUTORIAL
HERE IS THE SOURCE CODE!
// by Avraham Saltoun
// solutions at say-web dot com
// FREE to USE, COPY and DISTRIBUTE
var req:URLRequest = new URLRequest (“SmartSound.mp3″);
// this is the location of the sound file
var sound:Sound = new Sound();
// The sound class is the recepient for the
// imported sound file
var controller:SoundChannel;
// the controller sound channel
// will be used to play and stop the music file
var volumeControl:SoundTransform;
/* The volumeControl will handle the volume
level and must have a value between 0 and 1 */
function soundLoaded(event:Event):void {
controller = sound.play();
controller.stop();
// this will stop the file from playing
// right after loaded.
/* we must give a value to volume control variable
to start with */
volumeControl = controller.soundTransform;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
// the volume up and down buttons
up_btn.addEventListener(MouseEvent.CLICK,volumeUp);
down_btn.addEventListener(MouseEvent.CLICK,volumeDown);
}
function playSound(event:MouseEvent):void{
controller = sound.play();
}
function stopSound(event:MouseEvent):void {
controller.stop();
}
function volumeUp(event:MouseEvent):void {
volumeControl.volume = volumeControl.volume+0.1;
//now let’s check and see
//if it does not exceed 1
if (volumeControl.volume >1){volumeControl.volume = 1;}
//now let’s apply the new volume level!
controller.soundTransform = volumeControl;
}
function volumeDown(event:MouseEvent):void {
volumeControl.volume -= .1;
//now let’s check and see
//if it does not lower than 0
if (volumeControl.volume <0){volumeControl.volume = 0;}
//now let's apply the new volume level!
controller.soundTransform = volumeControl;
}
sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(req);
/*
I hope it helps
thanks for watching */






60 Responses to “Video Tutorial 30: ActionScript 3.0 Volume Controls for Your Flash Application”
Trackbacks/Pingbacks
ab346368@gmail.com…
Thank you for this interesting content. Your views have given me cause to reconsider some of my preconceived notions. You have changed my mind. That’s what I call persuasive writing….
ab346368@gmail.com…
My personal thoughts on this material are that it’s well-written, intelligent and easy to understand. I appreciate this kind of useful information, especially when it is this good. Thank you….
ab346368@gmail.com…
What you’ve done with this informational material is made it a real thinker’s article. It’s not very often that I find this kind of content and I really like it….
ab346368@gmail.com…
I’m impressed with your true talent for writing. It’s great to find a great article. I was motivated to tell you I appreciate your work….
ab346368@gmail.com…
When I find an article that gives me reason to use my brain, it really impresses me. You’re article gives readers a reason to think even long after it’s read….
ab346368@gmail.com…
Your article swept me away with its vast information and great writing. Thank you for sharing your views with such passion. I like your views….
ab346368@gmail.com…
Thank you for this very informative article. You have made sense of this topic by writing unique, original content. It’s easy to read, engaging and smart. Articles of this caliber are few and far between….
Title…
Wow that was strange. I just wrote an extremely detailed comment but after I clicked send my comment didn’t show up. Hmmm… well I’m not typing all that again. Anyways, just wanted to say great blog!…
Title…
Ugh, I just wrote a huge comment, but it disappeared when I hit send. Anyway, I’m not going to redo it again, so I just wanted to say cool blog! Better than http://facebook.com!
…
credit dispute letters…
[...]The information mentioned in the write-up are several of the top obtainable [...]…