is this code right or there is mistake

in my game, I got crash some times , when launch my game menu screen show up, when I press play game, I can play my game, when game is over, the first screen (( menu )) show up, but when I play again in Corona simulation is fine,
in my Iphone first time get crash . but when I quit the game then re launch it, I can play many time, but some time I got crash ,
I think about it, may be because I use (( BeebeGames )) with (( director 1.2)) file ??

because I do not know how to remove the Button listener , this is my menu screen codes.

[code]
module(…, package.seeall)


– IMPORTS


– GROUPS

–function new()
local localGroup = display.newGroup()

local ui = require (“ui”)

– DISPLAY OBJECTS

local background = display.newImage(“images/bgscreen1.png”)
local title = display.newText(“Shark Game”, 0, 0, native.systemFontBold, 20)

– BUTTONS


– FUNCTIONS

local function bt01t ( event )
if event.phase == “release” then

director:changeScene(“screen3”)
end
end

local function bt02t ( event )
if event.phase == “release” then

director:changeScene(“screen2”)
end
end


– UI OBJECTS

local bt01 = ui.newButton{
default = “images/startgame.png”,
over = “images/startgame.png”,
onEvent = bt01t,
id = “bt01”

}

local bt02 = ui.newButton{
default = “images/instruction.png”,
over = “images/instruction.png”,
onEvent = bt02t,
id = “bt02”

}

----------Frame update


– SLIDE


– IMAGE


– LISTENER


– INIT VARS

local function initVars ()


– Inserts

localGroup:insert(background)
localGroup:insert(title)

localGroup:insert(bt01)
localGroup:insert(bt02)


– Positions

title.x = 350
title.y = 80


bt01.x = 85
bt01.y = 80

bt02.x = 85
bt02.y = 200


– Colors

title:setTextColor( 180,180,180)


– Listeners

end


– CLEAN

function clean ( event )
print(“1 cleaned”)
end


– NEW

function new()


– Initiate variables

initVars()


– MUST return a display.newGroup()

return localGroup

end

[/code] [import]uid: 13061 topic_id: 8524 reply_id: 308524[/import]

seems like you have all the stuff, but just not in the right place.

try putting everything inside the function

like this:

[lua] local localGroup = display.newGroup()
function new()

– all code here

cleanUp = function ()

– cancel all timers
– cancel all transition in process

end

return localGroup

end – close the fuction and you’re done [import]uid: 12455 topic_id: 8524 reply_id: 31941[/import]