Well it must be something in my code. If I do this which is basically a distilled version of what I have in my code it works. Only thing that is weird is that it does print the print statement that shouldn’t be printed if I don’t cancel the timer. I have a purgeall and remove all in the new scene. But that is a different problem.
[code]
–
– scenetemplate.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local cancelTime
–
– NOTE:
– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– BEGINNING OF YOUR IMPLEMENTATION
local function switchScreen()
storyboard.gotoScene( “finish” )
end
local function timerStarter(event)
if event.phase == “began” then
local function delayer()
print (“This can’t show up, will crash before it can be printed”)
end
cancelTime=timer.performWithDelay(2000,delayer)
print(“start timer”)
end
return true
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
local button=display.newRect(group,100,100,50,50)
button:addEventListener(“touch”,timerStarter)
local exitButton=display.newRect(group,300,400,100,100)
button:addEventListener(“touch”,switchScreen)
exitButton:setFillColor(10, 100, 100)
– CREATE display objects and add them to ‘group’ here.
– Example use-case: Restore ‘group’ from previously saved state.
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
if cancelTime~= nil then
print(“cancelled timer”)
timer.cancel(cancelTime)
end
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
– INSERT code here (e.g. remove listeners, widgets, save state, etc.)
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene
[/code] [import]uid: 100901 topic_id: 35086 reply_id: 139556[/import]