mute - on/off button in scenes

  • Okay, I'm not a proger though, but my solution worked and that's enough *smile*

    Let's say we have a tour where 10 panos have sound "rock", one pano has sound "blues" and one "folk".

    I intoduced musictags within the scene node:

    Code
    <scene name="first_pano" title="Entrance" musictag="rock" >

    That'll help us to define what music to play.

    Now we need to have an 'onnewpano' event which will trigger the 'sound_check' action:

    Code
    <events name="music" keep="true" onnewpano="sound_check();" />

    While checking the music we have to trace the two conditions:

    a) what music must be played on the new scene. Above we intoduced the "musictag" which helps us define the music.
    b) if this music is shared among several panos, then we must know if the music has already been triggered and is now being played or is this the first time this very sound must be played.

    As our "rock" music is played in 10 panos, let's intoduce the "rock_music" variable which will be set to "running" or "notrunning" depending on the conditions.

    So now we can create an action called "sound_check":

    In the very beginning of the tour I started the sound immediately by:

    Code
    onstart="loadscene(get(scene[0].name));playsound (rock,'%SWFPATH%/sound/rock.mp3',0);set(rock_music, running);wait(blend);">

    So,now we have to create the button code to mute the sound. In the "sound_check();" action we have the "current_music" variable. This will help us to define what sound will be muted.
    I preferred to make the two methods for sound muting: in Flash it is "soft" - the sound interface is just tweened in volume to 0 in couple of seconds and the sound actually never stops playing. This is good when a user want to turn on the sound and it appears gradually to the full volume and doesn't hurt ears. In html5 it's not possible, so we must just stop the current sound.

    Here is the needed code for the button:

    Code
    onover="onoverA();"
     onoverA="showtext('Mute');"
     onoverB="showtext('Sound on');"
    	onclick="onclickA();"
    	onclickA="if(device.flash, tween(plugin[soundinterface].volume,0,2,EaseOutSine), pausesound(get(current_music)));set(onclick, onclickB(););set(onover, onoverB(););set(crop,'375|0|25|25');set(onovercrop,'375|25|25|25');"
    	onclickB="if(device.flash, tween(plugin[soundinterface].volume,0.5,2,EaseOutSine),resumesound(get(current_music)));set(onclick, onclickA(););set(onover, onoverA(););set(crop,'350|0|25|25');set(onovercrop,'350|25|25|25');"
        />

    Nevermind the crop and onovercrop values, yours are different anyway *tongue*

    Sooo... the button gets the "current_music" value and stops or resumes exactly it.


    I think, that's it *tongue* *tongue*

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!