FORUMS: list search recent posts

Sound and Volume Control in AS3

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Thaher Pelaseyed
Sound and Volume Control in AS3
on Jan 23, 2011 at 9:28:18 pm

Hi!

Adobe Flash CS4 Professional
AS 3.0

I have four buttons: play_btn, stop_btn, VolUp_btn and finally Vol Down_btn. It is a basic player with Play, Stop , Volume Up and Down buttons.

The code works just fine. It generates the player and the sound and volume control works.

But I want to use this player on a website and I want the visitors to hear the sound clip as soon as they enter the site. The visitors then have the choice to control the sound if they wish. With the code below, the visitor must first press play to start the sound clip.

Any Ideas?

Here is the AS 3.0 code (from this tutorial http://tutorials101.blogspot.com/2010/01/adjusting-volume-in-flash-actionsc....


var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("CheerfulSong.mp3");
var channel1:SoundChannel = new SoundChannel();
var volumeAdjust:SoundTransform = new SoundTransform();

volumeAdjust.volume = .5;

mySound.load(songURL);

play_btn.addEventListener(MouseEvent.CLICK, playSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
volUp_btn.addEventListener(MouseEvent.CLICK, volUp);
volDown_btn.addEventListener(MouseEvent.CLICK, volDown);

function playSound(e:MouseEvent):void
{
channel1 = mySound.play();
channel1.soundTransform = volumeAdjust;
}

function stopSound(e:MouseEvent):void
{
channel1.stop();
}

function volUp(e:MouseEvent):void
{
volumeAdjust.volume += .1;
if(volumeAdjust.volume <= 1)
{
channel1.soundTransform = volumeAdjust;
}
else
{
volumeAdjust.volume = 1;
channel1.soundTransform = volumeAdjust;
}
}

function volDown(e:MouseEvent):void
{
volumeAdjust.volume -= .1;
if(volumeAdjust.volume >= 0)
{
channel1.soundTransform = volumeAdjust;
}
else
{
volumeAdjust.volume = 0;
channel1.soundTransform = volumeAdjust;
}
}


Return to posts index


demetri tashie
Re: Sound and Volume Control in AS3
on Jan 23, 2011 at 11:22:19 pm

you can quite simply add these 2 lines to call them outside of the function:

channel1 = mySound.play();
channel1.soundTransform = volumeAdjust;

like this:
function playSound(e:MouseEvent):void
{
channel1 = mySound.play();
channel1.soundTransform = volumeAdjust;
}
channel1 = mySound.play();
channel1.soundTransform = volumeAdjust;


Return to posts index

Thaher Pelaseyed
Re: Sound and Volume Control in AS3
on Jan 24, 2011 at 10:45:19 am

Thanks a lot! Works superbly!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]