Hi all,
I’m very, very new to AS3 and still working it all out. I am building a small mp3 player and have created a mute button to accompany my volume slider, etc. Unfortunately I’m unable to get the thing to work. I tried to set up a Boolean variable called muted and do an if/then statement to correspond with the volume slider function, but it just mutes the whole thing from the start and won’t unmute.
Anyway, I’d appreciate any help! Thanks in advance
package com.audio
{
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.media.*;
public class VolumeSlider
{
public var vol:MovieClip;
public var volDrag:MovieClip;
public var volBar:MovieClip;
public var volBarX:Number;
public var volIcon:MovieClip;
public var soundIcon:MovieClip;
public var waveIcon:MovieClip;
public var player:Player;
public var dragging:Boolean = false;
public var muted:Boolean = false;
public function VolumeSlider(p:Player, v:MovieClip)
{
player = p;
vol = v;
volDrag = vol.slider_mc.drag_mc;
volBar = vol.slider_mc.bar_mc;
volBarX = volBar.x;
volIcon = vol.icon_mc;
soundIcon = vol.icon_mc.soundIcon_mc;
waveIcon = vol.icon_mc.wave_mc
vol.buttonMode = true;
volDrag.addEventListener(MouseEvent.MOUSE_DOWN, dragVol);
volIcon.addEventListener(MouseEvent.CLICK, muteOn)
}
//MUTE//
private function muteOn(Event):void
{
waveIcon.visible = false;
volIcon.addEventListener(MouseEvent.CLICK, muteOff)
//not working!!
muted = true;
}
private function muteOff(Event):void
{
waveIcon.visible = true;
volIcon.removeEventListener(MouseEvent.CLICK, muteOff)
muted = false;
}
//VOLUME SLIDER//
private function dragVol(event):void
{
volDrag.startDrag(false, new Rectangle(volBar.x,0,volBar.width-volDrag.width,0));
dragging=true;
player.stage.addEventListener(MouseEvent.MOUSE_UP, dropVolBar)
player.addEventListener(Event.ENTER_FRAME, updateVolume)
}
private function dropVolBar(event):void
{
if(dragging)
{
volDrag.stopDrag();
dragging=false;
player.stage.addEventListener(MouseEvent.MOUSE_UP, dropVolBar)
player.removeEventListener(Event.ENTER_FRAME, updateVolume)
}
}
public function updateVolume(event:Event=null):void
{
var trans:SoundTransform = player.channel.soundTransform;
var volPercent:Number = (volDrag.x-volBar.x)/(volBar.width-volDrag.width);
trans.volume = volPercent
//set mute--> this idea doesn't work!!
if(muted = true)
{
trans.volume = 0;
}
if(trans.volume > 1)
{
trans.volume = 1;
}
else if(trans.volume < 0)
{
trans.volume = 0;
}
//re-applies adjusted volume to SoundTranform
player.channel.soundTransform = trans;
}
}
}