audio buttons

Hi guys,

I am making an audio button, my question is how do you change the defaultFile image of the button when it has been clicked to reflect if there is or no sound.

What I want is that if a user clicks the button to mute or resume, the image of the button changes  accordingly and stays like that until the user clicks again.

thanks for your help.

[lua]

local function onSoundButtonEvent(event)

   local sound =event.target

     if (sound.status ==“waiting”) then

         audio.play(sounds[“intro”],{channel=1,loops=-1, fadein=500,})

         sound.status = “playing”

    elseif(sound.status ==“playing”) then

       audio.pause(1)

       sound.status = “paused”

    elseif(sound.status==“paused”)then

       audio.resume(1)

       sound.status=“playing”

    end

end

  local soundBtn = widget.newButton{

        labelColor = { default={255}, over={128} },

        defaultFile=“img/hud/audio.png”,

        overFile=“img/hud/audioOver.png”,

        width=60, height=60,

        onRelease= onSoundButtonEvent    

    }

 soundBtn.status=“waiting”

[/lua]

You don’t want a widget.newButton for this.  Button’s don’t have an on/off state.  They only have a is currently being pressed or not and trigger an action.   What you want is a widget.newSwitch.  Switchs maintain an on/off state.  In particular you should probably use a “checkbox” style switch.  It’s easily skinnable to have it look like you want.  You just need an image sheet with two identically sized frames, one for on, one for off and pass in a couple of parameters.

moving in the right direction now, thanks Rob!  :slight_smile:

You don’t want a widget.newButton for this.  Button’s don’t have an on/off state.  They only have a is currently being pressed or not and trigger an action.   What you want is a widget.newSwitch.  Switchs maintain an on/off state.  In particular you should probably use a “checkbox” style switch.  It’s easily skinnable to have it look like you want.  You just need an image sheet with two identically sized frames, one for on, one for off and pass in a couple of parameters.

moving in the right direction now, thanks Rob!  :slight_smile: