-
CS3/AS3: Volume Slider and Mute Button Compete
I've got a file with a streaming soundtrack (placed on the timeline for reasons I won't go into here) in which I'm trying to have both a volume slider and a toggle mute button (turns the sound on and off.) I've got them both incorporated in the Flash file, but they seem to be competing (volume slider works great, mute button not so much.) I'm a AS3 newbie and probably my code has some big errors in it, but I'll show it here. Any help how to fix this?
var soundVol:SoundTransform = new SoundTransform();
var transform1:SoundTransform = new SoundTransform();
var soundVolume:Number = 1;
var muted:Boolean = false;
// Code that handles the mute button
mute_mc.addEventListener(MouseEvent.CLICK, mute)
function mute(e:MouseEvent):void
{
var st:SoundTransform;
if (muted)
{
st = new SoundTransform(soundVolume);
SoundMixer.soundTransform = st;
mute_mc.gotoAndStop("On");
muted = false;
}
else
{
st = new SoundTransform(0);
SoundMixer.soundTransform = st;
mute_mc.gotoAndStop("Mute");
muted = true;
}
}
// Code that handles the sound volume
var ratio_volume:Number;
var trackBounds:Rectangle = track_mc.getBounds(track_mc);
var xPos:Number = trackBounds.x;
var yPos:Number = trackBounds.y;
var widthPos:Number = trackBounds.width-track_mc.slider_mc.width;
var heightPos:Number = 0;
var bounds:Rectangle = new Rectangle(xPos,yPos,widthPos,heightPos);
track_mc.slider_mc.x = widthPos;
track_mc.mouseEnabled = false;
track_mc.slider_mc.buttonMode = true;
track_mc.slider_mc.addEventListener(MouseEvent.MOU SE_DOWN,dragSlider);
stage.addEventListener(MouseEvent.MOUSE_UP,stopSli der);
function dragSlider(event:MouseEvent):void {
event.target.startDrag(false,bounds);
addEventListener(Event.ENTER_FRAME,setVolume);
}
function stopSlider(event:MouseEvent):void {
track_mc.slider_mc.stopDrag();
}
function setVolume(event:Event):void {
ratio_volume = track_mc.slider_mc.x/widthPos;
soundVol.volume = ratio_volume;
SoundMixer.soundTransform = soundVol;
}
Having trouble po
-
It looks like your slider adds an enterFrame that never gets removed again...so after you set volume once, you're resetting the volume every frame (which would stomp all over the mute)...try this in the stopSlider function:
PHP Code:
removeEventListener(Event.ENTER_FRAME, setVolume);
-
Yes, that did the trick! Hopefully I put this in the right place (see below)?
function stopSlider(event:MouseEvent):void {
track_mc.slider_mc.stopDrag();
removeEventListener(Event.ENTER_FRAME, setVolume);
}
-
That looks correct - if it's working now, you should be good to go.
-
slider source...?
Originally Posted by enjenk
Yes, that did the trick! Hopefully I put this in the right place (see below)?
function stopSlider(event:MouseEvent):void {
track_mc.slider_mc.stopDrag();
removeEventListener(Event.ENTER_FRAME, setVolume);
}
Hi, I am having a terrible time with a similar dilemma to yours except I don't need a mute toggle. I am trying to create a volume slider that will control sound in the timeline. I have found great code to do that but it's in ActionScript 2, as well as a host of AS3 sliders that load a URL or sound from the library but I need to have it in the timeline to synch with the animation. I saw your post and was ecstatic until i realized that I am not saavy enough to create the slider piece without seeing your source. I am pretty new at this - very beginner -level. Would you be willing to post that for me? I'd be grateful.
-
Here's an example that should show you how it works:
http://www.jijistudios.com/flash/VolSlider.zip
I think the key was using "SoundMixer" in place of
a library sound. Hope it works for you!
-
Thank you so much! This was very helpful.
tnx,
edie
-
enjenk,
I don't suppose you could show me your FLA file? I'm trying to do a mute button similar to what you did with an inserted streaming voice over. I'm SO BAD with AS to begin with, I'm so messed up trying to figure out AS3. I need to sit down for a few hours and start learning AS3, but I have to rush to get a project completed for a class I'm taking.
Any help would be appreciated!
Thanks!
-Darcie
-
enjenk,
the file u attached is perfect , could u or anyone else please tell me, how to show this volume slider on rollover.
i just want a volume slider like this but when i rollover a volume button then the slider should show.
plz plz help help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|