composer.gotoScene issue

Trying to change scenes but touch event continues to next scene.  

-requires local composer = require( "composer" ) local scene = composer.newScene() local myData = require( "scripts.myData" ) -- local forward references should go here -- local pageNumber = 1 local sceneName = "page1" local text = "1" local w = display.contentWidth local h = display.contentHeight local myText function nextPage() local options = { effect = "slideLeft", time = 10000, } goToPage = myData.currentPage + 1 if goToPage \> myData.lastPage then goToPage = myData.firstPage end composer.gotoScene( ("scripts.page" .. goToPage), options ) end --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- function onScreenTouch( event ) if event.phase == "ended" or event.phase == "cancelled" then print ("onScreenTouch " .. pageNumber ) -- Detect swipe direction and change scene if event.xStart \> event.x and (event.xStart - event.x) \>= 30 then nextPage() end myData.playText = 0 end return true end -- "scene:create()" function scene:create( event ) ----------------------------------------------------------------------------- -- CREATE display objects and add them to 'group' here. -- Example use-case: Restore 'group' from previously saved state. -- load audio ----------------------------------------------------------------------------- local sceneGroup = self.view --text myText = display.newText( text, 100, 100, native.systemFont, 48 ) sceneGroup:insert(myText) Runtime:addEventListener( "touch", onScreenTouch ) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then local group = self.view ----------------------------------------------------------------------------- -- This event requires build 2012.782 or later. ----------------------------------------------------------------------------- myData.currentPage = pageNumber elseif ( phase == "did" ) then -- 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 -- "scene:hide()" 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. Runtime:removeEventListener( "touch", onScreenTouch ) -- physics.pause elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. composer.removeScene( sceneName, true ) end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- 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 -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

You can’t add an event listener during while handling that same event. See:

http://docs.coronalabs.com/api/type/EventListener/addEventListener.html#gotchas

Try replacing the nextPage() call with timer.performWithDelay(1,nextPage)

You can’t add an event listener during while handling that same event. See:

http://docs.coronalabs.com/api/type/EventListener/addEventListener.html#gotchas

Try replacing the nextPage() call with timer.performWithDelay(1,nextPage)