I have a page in my app where I use an overlay to display some information. The user can exit the overlay screen by tapping on an exit button, which returns them to the original screen. From this screen, the can move to the next scene (I have a swipe handler in place to deal with this). Here is where my problem begins. After exiting the overlay and swiping, i get the following error instead of a page transition:
attempt to index global ‘scene’ (a nil value)
I’ve missed around with the code but can’t seem to solve the problem (or even work out whats causing the problem). Here is my code if that helps…
scene9.lua file:
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require(“widget”)
– Options table for the overlay scene “overlay.lua”
local overlayOptions = {
isModal = true,
effect = “crossFade”,
time = 400,
params = {
sampleVar = “my sample variable”
}
}
–options table for next page transitions
local pageChangeOptions = {
effect = “fromRight”,
time = 3000
}
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
local background = display.newImage(“Images/page9.png”, true)
background.x = display.contentWidth/2
background.y = display.contentHeight/2
sceneGroup:insert(background)
function loadOverlay(event)
composer.showOverlay( “overlay”, overlayOptions )
end
local infoButton = widget.newButton
{
width = 190,
height = 190,
id =“gate”,
defaultFile = “Images/infoButton.png”,
x = 175,
y = 225,
onEvent = loadOverlay
}
sceneGroup:insert(infoButton)
– swipe handler function
function swipeHandler(event)
if event.phase== “began” then
startTouchX = event.x
end
if event.phase == “ended” then
if event.x <= startTouchX - swipeDistance then
composer.gotoScene( “scene10”, pageChangeOptions )
end
end
return true
end
–event listeners
Runtime:addEventListener(“touch”, swipeHandler)
end
–overlay.lua file:
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require(“widget”)
–options table for next page transitions
local pageChangeOptions = {
effect = “fromRight”,
time = 3000
}
function exitOverlay()
composer.hideOverlay( “fade”, 400 )
end
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
local background = display.newImage(“Images/infographic1.png”, true)
background.x = display.contentWidth/2
background.y = display.contentHeight/2
local exitButton = widget.newButton
{
width = 190,
height = 190,
id =“exit”,
defaultFile = “Images/exitButton.png”,
x = 1900,
y = 150,
onEvent = exitOverlay
}
sceneGroup:insert(background)
sceneGroup:insert(exitButton)
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
local sceneGroup = self.view
local phase = event.phase
local parent = event.parent
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end