Need help with native.showalert()

The alert shows and dismisses ok, but when another button is touched the alert is back.

What am I doing wrong?
Hopefully some extra eyes can tell me.

Code as below is in file bdlogin.lua which is included in main.lua
A Login button in titlebar in main.lua calls the gotoLogin function in bdlogin.lua.

Works perfectly in simulator.
Works perfectly on device if alert is commented out, I.e. screen change correctly when Login or Back buttons pressed.

With alert in use and on device the alert pops up when changing to loginScreen.
On dismiss (OK touch) the alert dismisses.
Now for the yukk....
When the back button is touched the alert pops back up and the loginScreen redisplays instead of the slide to coffeeListScreen. I.e. it never goes back, just reactivates the alert and re-slides to loginScreen.

Please tell me where I'm screwing up. It's been driving me nuts as I have similar working on other pages and the sample fish app with alert works.

Of course my normal bdlogin.lua contains more code but I've trimmed it down in an effort to find my own mistakes, but have failed :-)

TIA

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- bdlogin.lua 
 
-- in main.lua
-- require("bdlogin")
-- coffeeListScreen = newScreen( 320, true, "Rare Parts", "stripes", false, "redtitlebg.png", nil, nil, 320, 1024 )
-- coffeeListScreen:addRightButton( "Login", gotoLogin, false, nil, nil, nil, nil, "redbtnleft.png", "redbtnmid.png","redbtnright.png", "custombtnleft-over.png", "custombtnmid-over.png", "custombtnright-over.png" )
 
-- loginScreen = newScreen( 320, true, "Account Login", "stripes", true, "redtitlebg.png" )
-- loginScreen:addLeftButton( "", goBackToFirstFromLogin, false, "redbackbtn.png", "custombackbtn-over.png" )
-- *******************************
 
 
goBackToFirstFromLogin = function (event )
        if event.phase == "release" then        
                loginScreen:slideToRight( coffeeListScreen )
        end
end
 
gotoLogin = function()
        local function onComplete( event )
        if "clicked" == event.action then
            local i = event.index
            if 1 == i then
                -- Do nothing; dialog will simply dismiss
            end
        end
        end
        local alert = native.showAlert( "Corona", "Alert test", { "OK" }, onComplete )
        coffeeListScreen:slideToLeft( loginScreen )
end

Hey there :)

Go;
CoronaSDK/SampleCode/Interface/Alert

Check out that sample app to see how native alerts are typically handled.

Peach :)

That's what I did and that's where most of the code comes from.

However, some changes were needed, mainly from placing alert at beginning of app to somewhere in the middle and in another file.

Note also, works elsewhere in similar situation, but not in above.

A pair of knowledgeable eyes will hopefully tell me where I went wrong, I.e. typo, usage, etc.

Thanks for trying, always appreciated.

Heinz

Even though I have a work-around in use in my App I'm still fussing with this.

I've come to a possible scenario... Once I dismiss the alert the back ground becomes 'hot' and when touched the page reloads, alert re-appears, etc. etc.

Not using any such events, intentionally at least. Back to examining code.

Finally....

If I call my login function via button press or release, all is well. I.e. gotoLogin()

If I call it via

1
addRightButton( "Login", gotoLogin, false, nil, nil, nil, nil, "redbtnleft.png", "redbtnmid.png", "redbtnright.png", "custombtnleft-over.png", "custombtnmid-over.png", "custombtnright-over.png" )

Last update... case closed.

Not 'exactly' sure where I went wrong because I ripped a lot of stuff apart. One of the drawbacks of my trial-and-error-programming style.

The end consensus though is that I had screwed up checking event results between keyboard and/or button. Between may be the wrong term but it was one or the other as I was trying to terminate input on a button release and also on keyboard return key press.

I'm back to using addRightButton and all is well.

Bottom line... user error confirmed... but fixed :)

views:1855 update:2011/10/1 9:04:19
corona forums © 2003-2011