Skip to main content
Participating Frequently
September 28, 2008
Answered

Mute button for sound in timeline

  • September 28, 2008
  • 3 replies
  • 5015 views
Greetings gurus. Pretty new to Flash CS3 and AS3 but I've done the Lynda.com courses and I've gotten by pretty far on my own. However, I've run into a snag I can't find a direct solution to. In the simplest possible terms I want to add a mute / unmute button for sound that must remain synced to my animation. It sounds like a pretty straightforward task and I'm embarased that THIS is where I've gotten stuck while I've gotten through some stuff I thought would be way harder on my own. The reason this is a problem is because in considering 2 approaches I've run into a wall. I'll gladly accept any advice to circumvent the roadblock either way.

Approach 1 is to add the sound to the library, drop it in the timeline as a stream and build my animation to match. That works just fine, but I can't find an instance name for the sound to run a setVolume function against (not even sure if it would be that simple, but without an instance name, I can't move any further forward; I tried labeling the first frame of the sound layer 'narration' and trying refernces like timeline.narration, timeline, narration, and so on, but no joy).

Approach 2 is to import the sound using URLRequest, instantiating the sound and setting the volume against that instance. Works like a charm but the sound drifts out of sync with the animation (that was synced perfectly when it was in the timeline). This is my less appealing option because I'm using nav buttons taking me to various frames and the sound (which used to pick up at the right frame when it was in the timeline) just plays on without regard to the point in the animation. It's not a surprise to me that this happens, but if I were to do this I'd need to write code into my nav buttons to pick up the right spot in the sound instance and I'm not sure how to do that.

Any help would be greatly appreciated.

Thanks,

Scott
This topic has been closed for replies.
Correct answer Colin Holgate
You can set the volume of everything like this:

var s:SoundTransform = new SoundTransform();
s.volume=vol;
SoundMixer.soundTransform=s;

where "vol" would be the volume you wanted, on a 0-1 scale.

In doing a mute feature you would normal remember the current volume in a variable, set the volume to zero, and then if you want to unmute you would set the volume back to the remembered value.


3 replies

Colin Holgate
Inspiring
October 13, 2008
No, you're safe as far as the OS volume goes. But imagine a typical video player, where there's a volume slider and a mute button, if you click the mute button twice, your process volume (ie, the video playing) should return to the volume as shown by the slider. It shouldn't be at a volume of 1, unless the slider happened to be at the top of its range.

An unusual variation of that would be if someone used the slider to go down to zero volume, then clicked the mute button twice, the video should still be at a volume of zero.

In most cases though the user would have the slider at a non-zero position.
Inspiring
October 12, 2008
good topic I need it too
sawoznyAuthor
Participating Frequently
October 12, 2008
Just as an FYI, Colin's answer contained a caveat that while the volume of the SoundTransform instance was set on a 0-1 scale to remember the pre-muting value so the overall sound level on reset would be the same as upon muting; however, I didn't need to do that. Now, I'm testing this on Vista which, based upon the behaviour of the volume control in this version of the OS, appears to have a sound mixer on a per-process basis which allows me to set the volume on the SoundTransform to 0 on mute and 1 (full volume for this process) on unmute and not modify the overall system volume. I'm going to try testing on Mac and earlier versions of Windows as Colin may be trying to warn that resetting the volume of the SoundTransform instance generated to 1 upon unmute in OSes other than Vista may reset the OVERALL system volume to 100% despite the fact the system volume was set to something less than that upon mute (not the desired behaviour). Thanks again Colin and hope this answer is useful to many of you. :)

Scott
Colin Holgate
Colin HolgateCorrect answer
Inspiring
October 1, 2008
You can set the volume of everything like this:

var s:SoundTransform = new SoundTransform();
s.volume=vol;
SoundMixer.soundTransform=s;

where "vol" would be the volume you wanted, on a 0-1 scale.

In doing a mute feature you would normal remember the current volume in a variable, set the volume to zero, and then if you want to unmute you would set the volume back to the remembered value.


sawoznyAuthor
Participating Frequently
October 11, 2008
Works like a charm. Thanks so much for your help. :)

Scott