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:

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

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


Trackbacks/Pingbacks

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


1,260
Unique Visitors
Previous 30 Days
Powered By Google Analytics