Corona Crashes when I use this Code

I don't know if this is a problem with my code or a problem with CoronaSDK, but whenever I use this code, when it tries to call the function (from Options button) it works but instantly crashes half a second later:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
local ui = require("ui")
function createmainmenu()
        Options = ui.newButton{
          default = "buttonBlue.png",
          over = "buttonBlueOver.png",
          onPress = clearmainmenu,
          onRelease = clearmainmenu,
          text = "Options",
          emboss = true
        }
end
function clearmainmenu()
        if Options ~= nil then
                Options:removeSelf()
        end
end
--Start
createmainmenu()

Your calling a function onPress to nil the button(Options) and then calling it again onRelease to nil the button but its already been removed causing the crash... i'd assume...

I removed the OnRelease part and forward declared the button and the functions, still a crash.

EDIT: If I change onpress to onrelease it works, kind of an annoying error (glitch?) but I guess its a good work around, thanks everyong.

views:1540 update:2011/10/6 9:28:12
corona forums © 2003-2011