• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Mute and unmute button is actionscript 3.0

Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

Hi,

I am wondering how to make a mute and unmute button is actionscript 3.0.  I did it before in actionscript 2.0 but not in 3.0.

Here is my actionscript 2.0 code.

var sound = 1;
var slashMC = _root.attachMovie("slash","slash01",99);
slash01._visible = false;
slashMC._y = btn._y;
slashMC._x = btn._x;
var s:Sound = new Sound();
s.attachSound("Gravy");
s.start(1,999);
btn.onPress = function(){
if(sound==1){
  s.stop();
  slash01._visible = true;
  sound = 0;
}
else if(sound==0){
  sound = 1;
  slash01._visible = false;
  s.start(1,999);
}
}

Thanks

TOPICS
ActionScript

Views

6.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

You could try something like this:

private function changeSound(event:MouseEvent)
{
    var st:SoundTransform = new SoundTransform();
    if(soundOn)
    {
        st.volume = 0;
        SoundMixer.soundTransform = st;
        soundIsOn = false;
    }
    else
    {
        st.volume = 1;
        SoundMixer.soundTransform = st;
        soundIsOn = true;
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

small correction to your code:

private function changeSound(event:MouseEvent)
{
    var st:SoundTransform = new SoundTransform();
    if(soundIsOn)
    {
        st.volume = 0;
        SoundMixer.soundTransform = st;
        soundIsOn = false;
    }
    else
    {
        st.volume = 1;
        SoundMixer.soundTransform = st;
        soundIsOn = true;
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

Thanks for the catch.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

Hi,

Where do I put the code.  Do I put it in frame 1.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

You can put it in frame one, on a seperate layer though. Also, if you're adding this to the timeline, take off the private part of the funciton.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

I put the code in frame one.  How do attach the sound because I dont hear the sound.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

My code now looks like this.  I removed private from private function...

var soundIsOn = true
function changeSound(event:MouseEvent)
{
    var st:SoundTransform = new SoundTransform();
    if(soundIsOn)
    {
        st.volume = 0;
        SoundMixer.soundTransform = st;
        soundIsOn = false;
    }
    else
    {
        st.volume = 1;
        SoundMixer.soundTransform = st;
        soundIsOn = true;
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

yeh that should be fine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

I don't here the sound.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

Dont I have to attach the sound somehow.

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

Here is another version.

var soundIsOn=true;
btn.addEventListener(MouseEvent.CLICK, changesound);
{
function changeSound(event:MouseEvent) {
  var st:SoundTransform = new SoundTransform();
  if (soundIsOn) {
   st.volume=0;
   SoundMixer.soundTransform=st;
   soundIsOn=false;
  } else {
   st.volume=1;
   SoundMixer.soundTransform=st;
   soundIsOn=true;
  }
}
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

the code provided before is ONLY for the mute functionality you need to create your soundobject as well.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

Try this:


    import flash.display.MovieClip;
    import flash.events.*;
    import flash.media.*;
    import flash.net.URLRequest;


        var isPlaying:Boolean = false;
        var snd:Sound = new Sound();
        var channel:SoundChannel = new SoundChannel();
        var pos:Number = 0;
        var soundVolume:Number = 1;
    
            snd.load(new URLRequest("something.mp3"));
            btn_Stop.addEventListener(MouseEvent.CLICK, stopMusic);
            btn_Stop.buttonMode = true;
           
            btn_Play.addEventListener(MouseEvent.CLICK, playMusic);
            btn_Play.buttonMode = true;
        
       
         function stopMusic(evt:Event):void
         {
            channel.stop();
            pos = 0;
            isPlaying = false;
         }
        
         function playMusic(evt:Event):void
         {
            if(!isPlaying)
            {
                channel = snd.play(pos);
                btn_Play.visible = false;
                btn_Pause.visible = true;
                isPlaying = true;
            }
         }
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2009 Apr 10, 2009

Copy link to clipboard

Copied

LATEST

Hi,

Thanks for the code.  I will look it over and post what happens.  Sorry about the delay.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines