on off switch help please

HI,

I have decided to use the widget libraries for a simple on/off button which switches music on and off.

Now I have looked at the examples and the docs but I am still not quite getting it.

I have used the radio button widget, I have it displayed and working.

I can get it turn the sound off but not back on.

I need to look for a flag true/false I guess so in my listener function I can:

[lua] if musicButton == true then

audio.play()

elseif muiscButton == false then

audio.stop()

[/lua]

An example would be good.

ok, thought I would post  quick bit of code.

I have the radio button working with a spritesheet but I cant figure the logic to switch sound on and switch sound off.

[lua]

local button3 = widget.newSwitch {
                    left = 120,
                    top = 180,
                    id = “button3”,
                    width = 32,
                    height = 32,
                    sheet = mySprites.sheets.button, mySprites.sequences.button,
                    frameOn = 2,
                    frameOff = 1,
                    style = “checkbox”,
                    onPress = musicButtonEvent,
                }

    group:insert( button3 )

[/lua]

[lua]

function musicButtonEvent (event)
                local switch = event.target

                        if switch.isOn  then
                        print(“soundoff”)

                        if switch.isOff then
                        print(“soundon”)
                        end
                        end

end

[/lua]

In an ideal world I would like to switch sound on and off with a regular button but cant seem to do it.

thank you

Ok, update.

I checked out the audio player sample, I was able to work it all out so now I have a nice sprited button which controls my audio.

ok, thought I would post  quick bit of code.

I have the radio button working with a spritesheet but I cant figure the logic to switch sound on and switch sound off.

[lua]

local button3 = widget.newSwitch {
                    left = 120,
                    top = 180,
                    id = “button3”,
                    width = 32,
                    height = 32,
                    sheet = mySprites.sheets.button, mySprites.sequences.button,
                    frameOn = 2,
                    frameOff = 1,
                    style = “checkbox”,
                    onPress = musicButtonEvent,
                }

    group:insert( button3 )

[/lua]

[lua]

function musicButtonEvent (event)
                local switch = event.target

                        if switch.isOn  then
                        print(“soundoff”)

                        if switch.isOff then
                        print(“soundon”)
                        end
                        end

end

[/lua]

In an ideal world I would like to switch sound on and off with a regular button but cant seem to do it.

thank you

Ok, update.

I checked out the audio player sample, I was able to work it all out so now I have a nice sprited button which controls my audio.

Having the same problem any tips? or example code would be great.

Having the same problem any tips? or example code would be great.

Thanks for telling us you figured it out.  Also, Thank you for not telling us what you did to figure the problem out.  I’m sure no one in the forums is having the same issue.

@Newbie_Programmer, he said how he solved it.  He went to the Audio sample app and got the code from there.  The samples are found under the CoronaSDK/SampleCode directory on your computer.

Please note:  I felt that this post was a bit on the “attack” side of things.  Please be careful with your wording on future posts.  You will find people are more responsive when you don’t put the on the defensive when you are asking for help.

Rob

Thanks for telling us you figured it out.  Also, Thank you for not telling us what you did to figure the problem out.  I’m sure no one in the forums is having the same issue.

@Newbie_Programmer, he said how he solved it.  He went to the Audio sample app and got the code from there.  The samples are found under the CoronaSDK/SampleCode directory on your computer.

Please note:  I felt that this post was a bit on the “attack” side of things.  Please be careful with your wording on future posts.  You will find people are more responsive when you don’t put the on the defensive when you are asking for help.

Rob