lua - BackBtn does not cancel timer from previous scene -


i can't find correct code cancel timers previous scenes. have tried these combinations in various positions:

      if "tap" == true            timer.cancel()       end             timer.cancel(event.source)        timer.cancel = true        timer.stop      if "tap" == true             timer.cancel = true             timer.stop()     end 

...and on. can point me correct code , place it? thanks. these scenes in question:

-- info.lua

local composer = require "composer" local scene = composer.newscene()  function scene:create(event)     local scenegroup = self.view      local widget = require "widget"     local scene1btn     local function onscene1btnrelease()             composer.gotoscene("scene1", "fade", 40)             return true      end      scene1btn = widget.newbutton{             defaultfile = "images/reviewtwo.png",             width= 480, height= 320,             onrelease = onscene1btnrelease      }      scenegroup:insert(scene1btn) end  scene:addeventlistener("create", scene)  return scene 

-- scene1.lua

    local mydata = require ("mydata")      local composer = require ( "composer")     local scene = composer.newscene()              local function showscene2()                     local options = {                             effect = "slideleft",                             time = 130,                     }     composer.gotoscene("scene2", options)     end     -- create scene       function scene:createscene ( event )     local scenegroup = self.view     end           function scene:show( event )     local scenegroup = self.view     local phase = event.phase  --                                                                           if ( phase == "will")             data = data + 1                     if data == 5                     sub = sub + 1                     data = 1             end             if sub == 3             section = section + 1                     sub = 1                     data = 1             end              background = display.newimage( "images/staveblankgrey2.png", 240, 160 )             note1 = display.newimage( "images/crdown.png", 130, 141 )             count = display.newimage( workouttable[section][sub][data], 60, 40 )               scenegroup:insert( background )             scenegroup:insert( note1 )             scenegroup:insert( count )   -- gobackbtn                                                                                              local object = display.newimage("images/gobackbtn.png", 240, 250)             object.name = "button object"              local function onobjecttap( self, event )                     composer.gotoscene( "info" )                     return true             end             object.tap = onobjecttap             object:addeventlistener( "tap", object )             scenegroup:insert( object )  -- did                                                                                                                        elseif ( phase == "did")             local function showscene2()                  local options = {                     effect = "slideleft",                     time = 30,                  }             composer.gotoscene( "scene2", options )             end              timer.performwithdelay( tempo, showscene2 )             end      end       -- hide / destroy      function scene:hide( event )             local scenegroup = self.view             local phase = event.phase     end      function scene:destroy( event )             local scenegroup = self.view     end      scene:addeventlistener( "create", scene )     scene:addeventlistener( "show", scene )     scene:addeventlistener( "hide", scene )     scene:addeventlistener( "destroy", scene )      return scene 

-- scene2.lua

    local composer = require ( "composer")     local scene = composer.newscene()              local function showscene1()                     local options = {                             effect = "slideleft",                             time = 130,                     }             composer.gotoscene("scene1", options)             end  -- create scene       function scene:createscene ( event )     local scenegroup = self.view     end           function scene:show( event )     local scenegroup = self.view     local phase = event.phase  --      if ( phase == "will")      background = display.newimage( "images/staveblankgrey2.png", 240, 160 )      note1 = display.newimage( "images/mmdown.png", 130, 172 )      scenegroup:insert( background )     scenegroup:insert( note1 )   -- gobackbtn      local object = display.newimage("images/gobackbtn.png", 240, 250)        object.name = "button object"         local function onobjecttap( self, event )             composer.gotoscene( "info" )             return true        end    object.tap = onobjecttap    object:addeventlistener( "tap", object )                     scenegroup:insert( object )  -- did     elseif ( phase == "did")        local function showscene1()            local options = {                 effect = "slideleft",                 time = 30,                                     }        composer.gotoscene( "scene1", options )        end         timer.performwithdelay(tempo, showscene1 )      end      end        -- hide / destroy      function scene:hide( event )             local scenegroup = self.view             local phase = event.phase     end      function scene:destroy( event )             local scenegroup = self.view     end      scene:addeventlistener( "create", scene )     scene:addeventlistener( "show", scene )     scene:addeventlistener( "hide", scene )     scene:addeventlistener( "destroy", scene )      return scene 

as assume, want cancel timer when go scene. use reference timer:

local mytimer1 = timer.performwithdelay(tempo, showscene1 ) 

and cancel in scene:hide or scene: destroy or anywhere else want to.

if mytimer1      timer.cancel(mytimer1)     mytimer1 = nil end 

of course have declare timer variable (mytimer1) in place you'll have access it. in main scope example


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -