Skip to main content
texjgc
Known Participant
December 14, 2008
Question

Simple Volume Control

  • December 14, 2008
  • 6 replies
  • 809 views
Hello.

Im having a bit of a struggle understanding volume control in AS3. I have never needed to do this but now I do....So if anyone can post me some ideas on how to start off my code I would very much appreciate it.

I just want the user to click a button and the volume (in my embedded flv) to turn off and on likewise when they click it again. I have a little piece of dynamic text that also I want to say "OFF" or "ON" depending on if the volume is on or off.

Thank you very much for any insight.
This topic has been closed for replies.

6 replies

Participating Frequently
December 20, 2008
You can buy a sound component rather cheaply. It doesn't seem like you have the coding experience to understand classes and the sound transform tool. I would just buy a component.


Sincerely,
Peter Roesler
Owner of a Web Design Company in Florida
texjgc
texjgcAuthor
Known Participant
December 18, 2008
ok sorry for no relaying the code. I used the following code:

function volON(evt:Event):void{
volBtn.gotoAndStop("OFF");
}
volBtn.addEventListener(MouseEvent.CLICK, volON);

function volOFF(evt:Event):void{
volBtn.gotoAndStop("ON");
}
volBtn.addEventListener(MouseEvent.CLICK, volOFF);

var myNetStrem:NetStream = new NetStream();
var mySoundTransform:SoundTransform = new SoundTransform();


I know it is not right I also dont know whats wrong with it....Thanks
Inspiring
December 19, 2008
What does line [volBtn.gotoAndStop("OFF");] accomplish from sound control stand point? Do you have a code in the frame "OFF"?

I don't see in the code snippet anything that manipulates volume.

The code I suggested should reside, perhaps, in the same scope where your NetStream is.
texjgc
texjgcAuthor
Known Participant
December 17, 2008
Ok, well I have tried and tried and wracked my brain the last few weeks to get this to work and it does not. There is either something I'm doing wrong or this code simply does not work.

The video I am using already has sound. For this code to work, do I need to have a separate sound track or does it matter? If this code works, what am I doing wrong?

But I repeat, the sound and the video are ONE file. This is really irritating (and why I stay away from programming altogether), so if anyone can please help me, I would appreciate it a lot. Thanks for the replies, so far.
Inspiring
December 18, 2008
texjgc,

The sound for the video is always part of the file - this is understood.

How can anyone tell if you are doing right or wrong thing if we don't see your code?

The approach I posted works all the time and using SoundTransform is the only way to manipulate video sound.
texjgc
texjgcAuthor
Known Participant
December 14, 2008
Am I reading the documentation wrong? Here is what I think it is saying to do....


volBtn.SoundTransform.volume:Number = 1;

function btnVolume(e:Event):void{
volBtn.SoundTransform.volume:Number = 0;
}
volBtn.addEventListener(MouseEvent.CLICK, btnVolume);



All I want is for the button to be clicked and the volume to come on or go off. There are no sliders or anything like that.
Inspiring
December 15, 2008
Well, unfortunately there is no way around learning AS3 and understanding of documentation, which is actually, very clear when AS3 concepts are grasped.

In your case, soundTransform is a property of NetStream - not a separate entity. So, if, say, you name your NetStream variable myNetStream:

var myNetStream:NetStream = new NetStream();

then you can manipulate its sound. In your function the mistake is that you attempt to call SoundTransform method on your button - not your NetStream. Unless the button has this method (or property) - it will not work.

Sound volume is a method of a separate class SoundTransform. So, you need a separate variable for it.

Another thing is that SoundTransform (with capital S) is a class name - not method name. Method starts with the lower "s".

I guess you functionality has to be rewritten:

var myNetStrem:NetStream = new NetStream();
var mySoundTransform:SoundTransform = new SoundTransform();

function btnVolume(e:Event):void{
mySoundTransform.volume = 0;
myNetStream.soundTransform = mySoundTransform;
}

to make the same function to do two things you can write a two-state switch:

function btnVolume(e:Event):void{
mySoundTransform.volume = 1 - mySoundTransform.volume;
myNetStream.soundTransform = mySoundTransform;
}

So, if the volume is 1 - it will become 0, if it is 0 - it will become 1.
texjgc
texjgcAuthor
Known Participant
December 14, 2008
Thanks for the reply, but I don't understand the documentation very well. My embedded movie has the sound intact. The sound is not a separate file.

If anyone can provide some sort of sample code that I can understand I would appreciate that. I have tried to find tutorials on this but there are not many out there that refer to as3. Or if someone can describe the documentation to me a bit better then that would also be helpful. Thank you.
Inspiring
December 14, 2008
Use soundTransform property of NetStream. Here is a link to documentation:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#soundTransform