Composer.showoverlay makes scene items appear for a half second and after that they are destroyed

I am trying to add a navbar to my home scene. I want to implement hamburger style menus. I am using composer.showoverlay to do it, but if i when I add items to scenegroup, they appear for a second and then they will be destroyed

-- home local composer = require( "composer" ) local widget = require( "widget" ) local scene = composer.newScene() local \_H = display.contentHeight local \_W = display.contentWidth --local chapter = require("app.chapter") local navbar = require("app.navbar") --1local book = require("app.book") local test = require("app.test") local navbar = require("app.navbar") function scene:create( event ) print("in create") -- composer.removeHidden(true) local sceneGroup = self.view --main = display.newGroup() scene.name = "app.home" local bg = display.newImageRect("res/home/background.png", \_W,\_H ) bg.x = \_W/2 bg.y = \_H/2 local customParams = { var1 = scene, var2 = "World!" } composer.showOverlay( "app.navbar", { effect="fade", params=customParams } ) --navbar = widget.navbar("home", "home", "home", "subhome", scene) sceneGroup:insert(bg) local function onKeyEvent( event ) -- Print which key was pressed down/up --local message = "Key '" .. event.keyName .. "' was pressed " .. event.phase --print( message ) -- If the "back" key was pressed on Android or Windows Phone, prevent it from backing out of the app if ( event.keyName == "back" ) then local platformName = system.getInfo( "platformName" ) print("android") if ( platformName == "Android" ) or ( platformName == "WinPhone" ) then return true end end -- IMPORTANT! Return false to indicate that this app is NOT overriding the received key -- This lets the operating system execute its default handling of the key return false end local function handleButtonEvent( event ) if ( "ended" == event.phase ) then --composer.gotoScene("app.book","fade") print(scene.name .. " scene name" ) --composer.removeScene("app.navbar") composer.removeScene(scene.name) print("after removal") end end -- Create the widget local button1 = widget.newButton { left = \_W/2, top = \_H/2, id = "button1", label = "Default", onEvent = handleButtonEvent } Runtime:addEventListener( "key", onKeyEvent ) sceneGroup:insert(button1) --[[local function checkMemory() print("IS HOME STILL OPENED" ) end timer.performWithDelay( 2000, checkMemory, 0 )]] end function scene:show( event ) --local sceneGroup = self.view local phase = event.phase print("in show") if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then local sceneGroup = self.view -- Called when the scene is now on screen -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc end end function scene:destroy( event ) print("Destroy HOME SCENE") local sceneGroup = self.view --sceneGroup:removeSelf() composer.removeScene("app.navbar") sceneGroup:removeSelf() -- sceneGroup = nil print("scenegroup destroyed in home") -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase print("in hide home") if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) elseif phase == "did" then -- Called when the scene is now off screen end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

-- navbar local \_H = display.contentHeight local \_W = display.contentWidth local widget = require( "widget" ) local rightHam = require("app.rightHam") local leftHam = require("app.leftHam") local composer = require( "composer" ) local scene = composer.newScene() --[[function widget.navbar( title, subtitle, topPic, underPic, homescene ) --create navbar and neccessart buttons local container = display.newContainer(\_W,\_H) local top\_bar local subBar if title == "home" then top\_bar = display.newImageRect("res/nav/top\_bar.png", \_W, \_H/10) top\_bar.y = top\_bar.height/2 top\_bar.x = \_W/2 local edFixLogo = display.newImage("res/nav/EdFix.png") edFixLogo.x = \_W/2 edFixLogo.y = top\_bar.height/2 else top\_bar = display.newImageRect("res/nav/" .. topPic .. ".png" , \_W, \_H/10) top\_bar.y = top\_bar.height/2 top\_bar.x = \_W/2 local title = display.newText( title, 100, 200, native.systemFont, 16 ) title.x = \_W/2 title.y = top\_bar.height/2 end print(underPic) local subBar = display.newImageRect("res/nav/" .. underPic .. ".png", \_W , top\_bar.height/2.5) subBar.y = top\_bar.height + subBar.height / 2 - 5 subBar.X = \_W/2 subBar.xScale = \_W local subtitle = display.newText( subtitle, 100, 200, native.systemFont, 40 ) subtitle.x = \_W/2 subtitle.y = subBar.y local leftNavBtn = display.newImageRect("res/nav/hamburger.png", 100, 100) leftNavBtn.id = " left ham" leftNavBtn.y = top\_bar.height/2 leftNavBtn.x = leftNavBtn.width/1.5 leftNavBtn:scale(0.5,0.5) local rightNavBtn = display.newImageRect("res/nav/rightHam.png", 100, 100) rightNavBtn.y = top\_bar.height/2 rightNavBtn.x = \_W - rightNavBtn.width/1.5 rightNavBtn:scale(0.5,0.5) --handle events on leftnavbtn function leftNavBtn:touch(event) if event.phase == "ended" then local overlay = display.newRect(\_W/2, \_H/2, \_W, \_H) overlay.alpha = 0 overlay.isHitTestable = true -- Only needed if alpha is 0 local leftHam = widget.leftHam(homescene) overlay:addEventListener("touch", function(event) if event.phase == "ended" and event.x \> display.contentWidth/2.7 then leftHam:close() overlay:removeSelf() end return true end) end end --hande events on rightnavbtn function rightNavBtn:touch(event) if event.phase == "ended" then local overlay = display.newRect(\_W/2, \_H/2, \_W, \_H) overlay.alpha = 0 overlay.isHitTestable = true -- Only needed if alpha is 0 local rightHam = widget.rightHam(homescene) overlay:addEventListener("touch", function(event) if event.phase == "ended" and event.x \< \_W -display.contentWidth/2.7 then rightHam:close() overlay:removeSelf() end return true end) end end container:insert(top\_bar) container:insert(subBar) rightNavBtn:addEventListener( "touch", listner ) leftNavBtn:addEventListener( "touch", listner ) return container end]] -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- -- local forward references should go here -- ------------------------------------------------------------------------------- function scene:create( event ) scene.name = "app.navbar" local sceneGroup = self.view --local nav = widget.navbar("home", "home", "home", "subhome", event.params.var1) --print( event.params.var1 ) --sceneGroup:insert(nav) --local container = display.newContainer(\_W,\_H) local top\_bar local subBar local edFixLogo local title = "home" local topPic = "home" local underPic = "subhome" local subtitle = "home" if title == "home" then top\_bar = display.newImageRect("res/nav/top\_bar.png", \_W, \_H/10) top\_bar.y = top\_bar.height/2 top\_bar.x = \_W/2 edFixLogo = display.newImage("res/nav/EdFix.png") edFixLogo.x = \_W/2 edFixLogo.y = top\_bar.height/2 else top\_bar = display.newImageRect("res/nav/" .. topPic .. ".png" , \_W, \_H/10) top\_bar.y = top\_bar.height/2 top\_bar.x = \_W/2 local title = display.newText( title, 100, 200, native.systemFont, 16 ) title.x = \_W/2 title.y = top\_bar.height/2 end local subBar = display.newImageRect("res/nav/" .. underPic .. ".png", \_W , top\_bar.height/2.5) subBar.y = top\_bar.height + subBar.height / 2 - 5 subBar.X = \_W/2 subBar.xScale = \_W local subtitle = display.newText( subtitle, 100, 200, native.systemFont, 40 ) subtitle.x = \_W/2 subtitle.y = subBar.y local leftNavBtn = display.newImageRect("res/nav/hamburger.png", 100, 100) leftNavBtn.id = " left ham" leftNavBtn.y = top\_bar.height/2 leftNavBtn.x = leftNavBtn.width/1.5 leftNavBtn:scale(0.5,0.5) local rightNavBtn = display.newImageRect("res/nav/rightHam.png", 100, 100) rightNavBtn.y = top\_bar.height/2 rightNavBtn.x = \_W - rightNavBtn.width/1.5 rightNavBtn:scale(0.5,0.5) --handle events on leftnavbtn function leftNavBtn:touch(event) if event.phase == "ended" then local overlay = display.newRect(\_W/2, \_H/2, \_W, \_H) overlay.alpha = 0 overlay.isHitTestable = true -- Only needed if alpha is 0 local leftHam = widget.leftHam(homescene) overlay:addEventListener("touch", function(event) if event.phase == "ended" and event.x \> display.contentWidth/2.7 then leftHam:close() overlay:removeSelf() end return true end) end end print(top\_bar.x , top\_bar.y .. " top.bar cordinates") --hande events on rightnavbtn function rightNavBtn:touch(event) if event.phase == "ended" then local overlay = display.newRect(\_W/2, \_H/2, \_W, \_H) overlay.alpha = 0 overlay.isHitTestable = true -- Only needed if alpha is 0 local rightHam = widget.rightHam(homescene) overlay:addEventListener("touch", function(event) if event.phase == "ended" and event.x \< \_W -display.contentWidth/2.7 then rightHam:close() overlay:removeSelf() end return true end) end end --sceneGroup:insert() --sceneGroup:insert() sceneGroup:insert(edFixLogo) sceneGroup:insert(top\_bar) sceneGroup:insert(subBar) rightNavBtn:addEventListener( "touch", listner ) leftNavBtn:addEventListener( "touch", listner ) --composer.removeScene(scene.name) -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then print("in did") -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view print("destroy in nacvbar") -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end -- "scene:destroy()" -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene