# Mute button, should be easy

**URL:** <https://forum.kirupa.com/t/mute-button-should-be-easy/300414>\
**Category:** flash\
**Created:** [November 20, 2009, 5:01pm UTC](https://forum.kirupa.com/t/mute-button-should-be-easy/300414 "2009-11-20T17:01:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arrow79](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@arrow79](https://forum.kirupa.com/u/arrow79)\
**Post date:** [November 20, 2009, 5:01pm UTC](https://forum.kirupa.com/t/mute-button-should-be-easy/300414/1 "2009-11-20T17:01:57Z")

</div>

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

```php
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;
            
            }

        
    }
    
}

```
