Skip to main content
Known Participant
December 23, 2008
Answered

Sound Volume Control

  • December 23, 2008
  • 8 replies
  • 1211 views
If I have library song playing using a simple code like:
var mySong:Song = new Song();
mySong.play();
How do I use a button to control its volume so that each time it is clicked the volume goes up or down by a little.
Thanks for your help.
This topic has been closed for replies.
Correct answer kglad
Yes that's the idea, I think. it starts at 1 then each click should take it down further. Of course I like to be able to increase it after it goes down so far, say 0. What would I add to the existing code to accomplish that?
Thanks

:

8 replies

kglad
Community Expert
Community Expert
December 24, 2008
you're welcome.
irajiAuthor
Known Participant
December 24, 2008
I understand. I believe this will do nicely. Thanks for your help, I believe I understand it better now.
Thanks
kglad
Community Expert
Community Expert
December 24, 2008
i don't know how you want one button it to work. i can't think of any natural way to make one button work to increase and decrease volume that would be obvious to users.

for example, you could make the button a toggle so on all odd numbered clicks the volume decreases and on even clicks it increases, but this probably wouldn't be intuitive for users.
irajiAuthor
Known Participant
December 24, 2008
Thanks Kglad. I guess twobuttons would work for now but I'm curious how I would go about using only one button. I tried the if else but that doesn't work since as soon as I click the button its less than or greater than and switches. Any idea?
Thanks
kglad
Community Expert
Community Expert
December 24, 2008
i coded it for two buttons, but you can do it with one button. you just need some kind of logic to indicate when the volume should increase and when it should decrease.
irajiAuthor
Known Participant
December 23, 2008
Well, in trying it I found the volume to go up OK but it didn't reduce. If I add another button for that, then it works fine and the volume can go up or down. I guess there's no way one button can do that?
Thanks
irajiAuthor
Known Participant
December 23, 2008
Thanks Hglad, very nice. Will this not need a little extra code, something like an if else for vol=1 and vol=0 to increase or decrease? This doesn't work as it is.
kglad
Community Expert
Community Expert
December 23, 2008
the play() method returns a soundchannel instance for your sound (assuming Song extends the Sound class) and the soundchannel class has a soundTransform property that has a volume property you can control.
irajiAuthor
Known Participant
December 23, 2008
Could you elaborate with a little code please. I am new to AS3.
Thanks
kglad
Community Expert
Community Expert
December 23, 2008
: