Video Tutorial 30: ActionScript 3.0 Volume Controls for Your Flash Application

Wed, Sep 9, 2009

ActionScript

CLICK THE PLAY BUTTON TO HEAR THE MUSIC AND USE THE ARROWS TO SHIFT THE VOLUME UP OR DOWN (TAKES A FEW SECONDS TO LOAD… WORKS GUARANTEED!)
This movie requires Flash Player 9

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!

//The ActionScript 3.0 Flash Volume Controls
// 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 */

Related Articles:

, , , , , , , , , , , , , , , , , , , , ,

60 Responses to “Video Tutorial 30: ActionScript 3.0 Volume Controls for Your Flash Application”


Trackbacks/Pingbacks

  1. Digital says:

    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….

  2. oral says:

    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….

  3. hausfrau says:

    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….

  4. 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….

  5. 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….

  6. 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….

  7. video says:

    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….

  8. tatuaggi says:

    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!…

  9. SEO Company says:

    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! :-)

  10. credit dispute letters…

    [...]The information mentioned in the write-up are several of the top obtainable [...]…

Leave a Reply

You must be logged in to post a comment.

My name is Avraham Saltoun, and I live in Jerusalem, Middle East. I am currently on my mid  40's and I am a computer programming technician. Here you will find over one hundred quality video tutorials on Actionscript, and yes, I give online support for aspiring programmers, and pros as well, sharing screen on skype and delivering source code by email, click the button for live flash actionscript support now!

 
oDesk Certified Action Script Programmer
oDesk Certified Adobe Flash CS3 Designer
oDesk Certified Adobe Photoshop 6.0 Designer
Skype Me™!

$7.49 .Com! Score Savings Cartoon Smart Tutorials


839
Unique Visitors
Previous 30 Days
Powered By Google Analytics