문제

I have this action script code that is working perfectly but i am try to reverse the process where the movie starts without any sound, and then when you click the button the music will be unmuted.

It seems i can't figure out how to do this. Maybe some one can show me how it is done, i really know nothing about action script 3

function setMute(vol){
var sTransform:SoundTransform = new SoundTransform(0,0);
sTransform.volume = vol; SoundMixer.soundTransform = sTransform;
}
var Mute:Boolean = false;
mutebutton.addEventListener
(MouseEvent.CLICK,toggleMuteBtn);
function toggleMuteBtn(event:Event){ if(Mute){ Mute = false; setMute(1);
mutte.gotoAndStop(1); }
else{ Mute = true; 
setMute(0);
mutte.gotoAndStop(2); }
}

Thanks for the help.

도움이 되었습니까?

해결책

  1. Change function toggleMuteBtn(event:Event) =>

    function toggleMuteBtn(event:Event = NULL)

    This allows you to call the function without triggering an Event.

  2. Use toggleMuteBtn(); anywhere you need to mute/unmute. Using it once when the application starts will set your initial state to muted instead of unmuted.

다른 팁

this is the code as it should be working to have movie start with muted sound and then when you click a button the sound will be turned on.

var mute:Boolean = false;
var st:SoundTransform;// <- variable is exposed to all functions in this script

mutebutton.addEventListener(MouseEvent.CLICK,toggleMuteBtn);

function toggleMuteBtn(event:Event = null)
{
    if (mute)
    {
        setMute(1,1);
    }
    else
    {
        setMute(0,2);
    }
    // toggle the mute Boolean
    mute = !mute;
}

function setMute(vol:Number, frm:Number):void
{
    st = new SoundTransform(0,0);
    st.volume = vol;
    SoundMixer.soundTransform = st;
    mutte.gotoAndStop(frm);
}
toggleMuteBtn();

`

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top