Hi, I have facing this problem since i started to develop app using corona sdk. My app cannot back to previous screen after I have run through 3 screen. Can anyone help me have a look on my code and help solve it? Thank you.
a.lua
--------------------------------------------------------------------------------- -- -- scene2.lua -- --------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local chicken, asound local image, text1, aButton, homeButton, nextButton, aButton local function onSceneTouch( self, event ) if event.phase == "ended" then audio.pause(asound) audio.pause(chicken) audio.pause(sound) composer.gotoScene( "phonics.alphabet.b", "fade", 400 ) return true end end local function aButtonTouch( self, event ) if event.phase == "ended" then if aButton.sequence == "idle" then aButton:setSequence("run") audio.pause (chicken) audio.pause(sound) audio.play (asound) elseif aButton.sequence == "run" then aButton:setSequence("idle") end aButton:play() return true end end local function homeButtonTouch( self, event ) if event.phase == "ended" then audio.pause(asound) audio.pause(chicken) audio.pause(sound) composer.gotoScene( "menu", "fade", 400 ) return true end end local function ayamTouch( self, event ) if event.phase == "ended" then audio.pause(asound) audio.pause(sound) audio.play (chicken) return true end end local function nextButtonTouch( self, event ) if event.phase == "ended" then audio.pause(asound) audio.pause(chicken) audio.pause(sound) composer.gotoScene( "phonics.alphabet.b", "slideLeft", 400 ) return true end end local function chickTouch( self, event ) if event.phase == "ended" then if chick.sequence == "idle" then chick:setSequence("run") audio.pause (asound) audio.pause (chicken) audio.play(sound) elseif chick.sequence == "run" then chick:setSequence("idle") end chick:play() return true end end function scene:create( event ) local sceneGroup = self.view asound = audio.loadSound("sound/reading/alphabet/a.wav") chicken = audio.loadSound("sound/reading/word/chicken.mp3") sound = audio.loadSound("sound/reading/word/chickensound.mp3") image = display.newImage( "background/UI\_sebutanABC.png" ) image.x = 515 image.y = 385 sceneGroup:insert( image ) image.touch = onSceneTouch text1 = display.newText( "Scene 2", 0, 0, native.systemFontBold, 24 ) text1:setFillColor( 255 ) text1.x, text1.y = display.contentWidth \* 0.5, 50 sceneGroup:insert( text1 ) local options2 = { width = 360, height = 295, numFrames = 5 } local sheet = graphics.newImageSheet("image/Combine/Aa.png" , options2) local sequence = { {name="run", start=1, count=5, time=1000}, {name="idle", start=5, count=5, time=100} } aButton = display.newSprite(sheet, sequence) aButton:addEventListener("sprite", function(event) if aButton.loopCount == 2 then aButton.loopCount = 0 aButton:setSequence("idle") aButton:play() end if event.phase == "loop" then aButton.loopCount = aButton.loopCount + 1 end end) aButton.x = 300 aButton.y = 250 aButton:setSequence("idle") aButton:play() aButton.loopCount = 0 sceneGroup:insert( aButton ) aButton.touch = aButtonTouch local options = { width = 275, height = 397, numFrames = 4 } local sheet = graphics.newImageSheet("image/image\_word/chicken.png" , options) local sequence = { {name="run", start=1, count=5, time=500}, {name="idle", start=5, count=5, time=150} } chick = display.newSprite(sheet, sequence) chick:addEventListener("sprite", function(event) if chick.loopCount == 2 then chick.loopCount = 0 chick:setSequence("idle") chick:play() end if event.phase == "loop" then chick.loopCount = chick.loopCount + 1 end end) chick.x = 700 chick.y = 495 chick:setSequence("idle") chick:play() chick.loopCount = 0 sceneGroup:insert( chick ) chick.touch = chickTouch ayam = display.newImage( "image/image\_word/ayam.png" ) ayam.x = 700 ayam.y = 690 sceneGroup:insert( ayam ) ayam.touch = ayamTouch homeButton = display.newImage( "button/home.png" ) homeButton.x = 960 homeButton.y = 50 sceneGroup:insert( homeButton ) homeButton.touch = homeButtonTouch nextButton = display.newImage( "button/next.png" ) nextButton.x = 960 nextButton.y = 720 sceneGroup:insert( nextButton ) nextButton.touch = nextButtonTouch print( "\n2: create event" ) end function scene:show( event ) local phase = event.phase if "did" == phase then print( "2: show event, phase did" ) -- remove previous scene's view composer.removeScene( "menu" ) -- Update Lua memory text display image:addEventListener( "touch", image ) nextButton:addEventListener( "touch", nextButton ) homeButton:addEventListener( "touch", homeButton ) ayam:addEventListener( "touch", ayam ) aButton:addEventListener( "touch", aButton ) chick:addEventListener("touch", chick) audio.play(asound) audio.play(chicken) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "2: hide event, phase will" ) -- remove touch listener for image image:removeEventListener( "touch", image ) nextButton:removeEventListener( "touch", nextButton ) homeButton:removeEventListener( "touch", homeButton ) ayam:removeEventListener( "touch", ayam ) aButton:removeEventListener( "touch", aButton ) chick:removeEventListener( "touch", chick ) end end function scene:destroy( event ) print( "((destroying scene 2's view))" ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
b.lua
--------------------------------------------------------------------------------- -- -- scene2.lua -- --------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local beruang, bsound local image, text1, bButton, homeButton, nextButton, bButton local function onSceneTouch( self, event ) if event.phase == "ended" then audio.pause(bsound ) audio.pause(bearsound) audio.pause(sound) composer.gotoScene( "phonics.alphabet.c", "fade", 400 ) return true end end local function bButtonTouch( self, event ) if event.phase == "ended" then if bButton.sequence == "idle" then bButton:setSequence("run") audio.pause (bearsound) audio.pause(sound) audio.play (bsound ) elseif bButton.sequence == "run" then bButton:setSequence("idle") end bButton:play() return true end end local function homeButtonTouch( self, event ) if event.phase == "ended" then audio.pause(bsound ) audio.pause(bearsound) audio.pause(sound) composer.gotoScene( "menu", "fade", 400 ) return true end end local function previousButtonTouch( self, event ) if event.phase == "ended" then audio.pause(bsound ) audio.pause(bearsound) audio.pause(sound) composer.gotoScene( "phonics.alphabet.a", "slideLeft", 400 ) return true end end local function beruangTouch( self, event ) if event.phase == "ended" then audio.pause(bsound ) audio.pause(sound) audio.play (bearsound) return true end end local function nextButtonTouch( self, event ) if event.phase == "ended" then audio.pause(bsound ) audio.pause(bearsound) audio.pause(sound) composer.gotoScene( "phonics.alphabet.c", "slideLeft", 400 ) return true end end local function bearTouch( self, event ) if event.phase == "ended" then if bear.sequence == "idle" then bear:setSequence("run") audio.pause (bsound ) audio.pause (bearsound) audio.play(sound) elseif bear.sequence == "run" then bear:setSequence("idle") end bear:play() return true end end function scene:create( event ) local sceneGroup = self.view bsound = audio.loadStream("sound/reading/alphabet/b.wav") bearsound = audio.loadStream("sound/reading/word/beruang.mp3") sound = audio.loadStream("sound/reading/word/bear.wav") image = display.newImage( "background/UI\_sebutanABC.png" ) image.x = 515 image.y = 385 sceneGroup:insert( image ) image.touch = onSceneTouch text1 = display.newText( "Scene b", 0, 0, native.systemFontBold, 24 ) text1:setFillColor( 255 ) text1.x, text1.y = display.contentWidth \* 0.5, 50 sceneGroup:insert( text1 ) local options2 = { width = 354, height = 300, numFrames = 5 } local sheet = graphics.newImageSheet("image/Combine/Bb.png" , options2) local sequence = { {name="run", start=1, count=5, time=1000}, {name="idle", start=5, count=5, time=100} } bButton = display.newSprite(sheet, sequence) bButton:addEventListener("sprite", function(event) if bButton.loopCount == 2 then bButton.loopCount = 0 bButton:setSequence("idle") bButton:play() end if event.phase == "loop" then bButton.loopCount = bButton.loopCount + 1 end end) bButton.x = 300 bButton.y = 250 bButton:setSequence("idle") bButton:play() bButton.loopCount = 0 sceneGroup:insert( bButton ) bButton.touch = bButtonTouch local options = { width = 302, height = 287, numFrames = 3 } local sheet = graphics.newImageSheet("image/image\_word/bear.png" , options) local sequence = { {name="run", start=1, count=5, time=800}, {name="idle", start=4, count=5, time=150} } bear = display.newSprite(sheet, sequence) bear:addEventListener("sprite", function(event) if bear.loopCount == 2 then bear.loopCount = 0 bear:setSequence("idle") bear:play() end if event.phase == "loop" then bear.loopCount = bear.loopCount + 1 end end) bear.x = 700 bear.y = 495 bear:setSequence("idle") bear:play() bear.loopCount = 0 sceneGroup:insert( bear ) bear.touch = bearTouch beruang = display.newImage( "image/image\_word/Beruang.png" ) beruang.x = 700 beruang.y = 690 sceneGroup:insert( beruang ) beruang.touch = beruangTouch homeButton = display.newImage( "button/home.png" ) homeButton.x = 960 homeButton.y = 50 sceneGroup:insert( homeButton ) homeButton.touch = homeButtonTouch nextButton = display.newImage( "button/next.png" ) nextButton.x = 960 nextButton.y = 720 sceneGroup:insert( nextButton ) nextButton.touch = nextButtonTouch previousButton = display.newImage( "button/previous.png" ) previousButton.x = 60 previousButton.y = 720 sceneGroup:insert( previousButton ) previousButton.touch = previousButtonTouch print( "\n2: create event" ) end function scene:show( event ) local phase = event.phase if "did" == phase then print( "2: show event, phase did" ) -- remove previous scene's view composer.removeScene( "menu" ) -- Update Lua memory text display image:addEventListener( "touch", image ) nextButton:addEventListener( "touch", nextButton ) homeButton:addEventListener( "touch", homeButton ) beruang:addEventListener( "touch", beruang ) bButton:addEventListener( "touch", bButton ) bear:addEventListener("touch", bear) previousButton:addEventListener( "touch", previousButton ) audio.play(bsound ) audio.play(bearsound) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "2: hide event, phase will" ) -- remove touch listener for image image:removeEventListener( "touch", image ) nextButton:removeEventListener( "touch", nextButton ) homeButton:removeEventListener( "touch", homeButton ) beruang:removeEventListener( "touch", beruang ) bButton:removeEventListener( "touch", bButton ) bear:removeEventListener( "touch", bear ) previousButton:removeEventListener( "touch", previousButton ) end end function scene:destroy( event ) print( "((destroying scene 2's view))" ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
c.lua
--------------------------------------------------------------------------------- -- -- scene2.lua -- --------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local cicaksound, csound local image, text1, cButton, homeButton, nextButton, cButton local function onSceneTouch( self, event ) if event.phase == "ended" then audio.pause(csound) audio.pause(sound) audio.pause (cicaksound) --composer.gotoScene( "phonics.alphabet.d", "fade", 400 ) return true end end local function cButtonTouch( self, event ) if event.phase == "ended" then if cButton.sequence == "idle" then cButton:setSequence("run") audio.pause (cicaksound) audio.pause(sound) audio.play (csound) elseif cButton.sequence == "run" then cButton:setSequence("idle") end cButton:play() return true end end local function homeButtonTouch( self, event ) if event.phase == "ended" then audio.pause(csound) audio.pause(sound) audio.play (cicaksound) composer.gotoScene( "menu", "fade", 400 ) return true end end local function previousButtonTouch( self, event ) if event.phase == "ended" then audio.pause(csound) audio.pause(sound) audio.pause(cicaksound) composer.gotoScene( "phonics.alphabet.b", "slideLeft", 400 ) return true end end local function lizardTouch( self, event ) if event.phase == "ended" then audio.pause(csound) audio.pause(sound) audio.pause (cicaksound) return true end end local function nextButtonTouch( self, event ) if event.phase == "ended" then audio.pause(csound) audio.pause(cicaksound) audio.pause(sound) --composer.gotoScene( "phonics.alphabet.d", "slideLeft", 400 ) return true end end local function cicakTouch( self, event ) if event.phase == "ended" then if cicak.sequence == "idle" then cicak:setSequence("run") audio.pause (csound) audio.pause (cicaksound) audio.play(sound) elseif cicak.sequence == "run" then cicak:setSequence("idle") audio.pause(sound) end cicak:play() return true end end function scene:create( event ) local sceneGroup = self.view csound = audio.loadSound("sound/reading/alphabet/c.wav") cicaksound = audio.loadSound("sound/reading/word/cicak.mp3") sound = audio.loadSound("sound/reading/word/lizardsound.mp3") image = display.newImage( "background/UI\_sebutanABC.png" ) image.x = 515 image.y = 385 sceneGroup:insert( image ) image.touch = onSceneTouch text1 = display.newText( "Scene c", 0, 0, native.systemFontBold, 24 ) text1:setFillColor( 255 ) text1.x, text1.y = display.contentWidth \* 0.5, 50 sceneGroup:insert( text1 ) local options2 = { width = 380, height = 270, numFrames = 5 } local sheet = graphics.newImageSheet("image/Combine/Cc.png" , options2) local sequence = { {name="run", start=1, count=5, time=1000}, {name="idle", start=5, count=5, time=100} } cButton = display.newSprite(sheet, sequence) cButton:addEventListener("sprite", function(event) if cButton.loopCount == 2 then cButton.loopCount = 0 cButton:setSequence("idle") cButton:play() end if event.phase == "loop" then cButton.loopCount = cButton.loopCount + 1 end end) cButton.x = 300 cButton.y = 250 cButton:setSequence("idle") cButton:play() cButton.loopCount = 0 sceneGroup:insert( cButton ) cButton.touch = cButtonTouch local options = { width = 215, height = 320, numFrames = 10 } local sheet = graphics.newImageSheet("image/image\_word/cicak.png" , options) local sequence = { {name="run", start=1, count=5, time=500}, {name="idle", start=15, count=5, time=150} } cicak = display.newSprite(sheet, sequence) cicak:addEventListener("sprite", function(event) if cicak.loopCount == 2 then cicak.loopCount = 0 cicak:setSequence("idle") cicak:play() end if event.phase == "loop" then cicak.loopCount = cicak.loopCount + 1 end end) cicak.x = 700 cicak.y = 495 cicak:setSequence("idle") cicak:play() cicak.loopCount = 0 sceneGroup:insert( cicak ) cicak.touch = cicakTouch lizard = display.newImage( "image/image\_word/lizard.png" ) lizard.x = 700 lizard.y = 690 sceneGroup:insert( lizard ) lizard.touch = lizardTouch homeButton = display.newImage( "button/home.png" ) homeButton.x = 960 homeButton.y = 50 sceneGroup:insert( homeButton ) homeButton.touch = homeButtonTouch nextButton = display.newImage( "button/next.png" ) nextButton.x = 960 nextButton.y = 720 sceneGroup:insert( nextButton ) nextButton.touch = nextButtonTouch previousButton = display.newImage( "button/previous.png" ) previousButton.x = 60 previousButton.y = 720 sceneGroup:insert( previousButton ) previousButton.touch = previousButtonTouch print( "\n2: create event" ) end function scene:show( event ) local phase = event.phase if "did" == phase then print( "2: show event, phase did" ) -- remove previous scene's view -- Update Lua memory text display image:addEventListener( "touch", image ) nextButton:addEventListener( "touch", nextButton ) homeButton:addEventListener( "touch", homeButton ) lizard:addEventListener( "touch", lizard ) cButton:addEventListener( "touch", cButton ) cicak:addEventListener("touch", cicak) previousButton:addEventListener( "touch", previousButton ) audio.play(csound) audio.play(cicaksound) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "2: hide event, phase will" ) -- remove touch listener for image image:removeEventListener( "touch", image ) nextButton:removeEventListener( "touch", nextButton ) homeButton:removeEventListener( "touch", homeButton ) lizard:removeEventListener( "touch", lizard ) cButton:removeEventListener( "touch", cButton ) cicak:removeEventListener( "touch", cicak ) previousButton:removeEventListener( "touch", previousButton ) end end function scene:destroy( event ) print( "((destroying scene 2's view))" ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene