When I build my app I have a few textboxes on one of my scenes and i;m using a scrollview with all the textboxes in, now when I change the scene the textboxes don’t disappear like I thought they and I have no idea why. Does anyone know? My code looks like this and I’ve also attached my source documents.
[lua]
–
– home.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
function scene:create( event )
local sceneGroup = self.view
– Called when the scene’s view does not exist.
–
– INSERT code here to initialize the scene
– e.g. add display objects to ‘sceneGroup’, add touch listeners, etc.
– Scroll
local scrollView = widget.newScrollView
{
top = - 28,
left = 0,
width = display.contentWidth,
height = display.contentHeight + 20,
horizontalScrollDisabled = true,
scrollHeight = 480,
listener = scrollListener,
topPadding = 25
}
–Scene Backgroud
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 1 ) – white
scrollView:insert( bg )
–Scene Title
local title = display.newText( “Incident Reporting”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = -10
scrollView:insert( title )
–text1
local text1 = display.newText(“THIS FORM SHOULD BE USED BY STAFF AND STUDENTS TO REPORT ANY INCIDENT OR NEAR MISS. PLEASE PROVIDE AS MUCH INFORMATION AS YOU CAN. IN SOME CASES THE SAFETY, HEALTH & WELLBEING DEPARTMENT MAY CONTACT YOU FOR MORE INFORMATION. THE WE ENCOURAGE ALL STAFF TO REPORT INCIDENTS AND NEAR MISSES AND THE FACTUAL INFORMATION YOU TELL US WILL BE REVIEWED AND USED AS AN OPPORTUNITY TO LEARN AND IMPROVE.”,
160, 150, display.contentWidth -25 , display.contentHeight * 0.5, native.systemFont, 12 )
text1:setFillColor( 0, 0, 0 )
scrollView:insert( text1 )
–divider
local divider = display.newImage( “divider.png” )
divider:translate( 160, 170 )
scrollView:insert( divider )
–textSectionA
local textSectionA = display.newText(“Section A: About the Incident”,
172, 315, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 20 )
textSectionA:setFillColor( 0, 0, 0 )
scrollView:insert( textSectionA )
–textDate
local textDate = display.newText(“Incident Date: (DD/MM/YY)”,
175, 350, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textDate:setFillColor( 0, 0, 0 )
scrollView:insert( textDate )
–textBoxDay
local textBoxDay = native.newTextField( 54, 270, 75, 40 )
textBoxDay.size = 20
textBoxDay:addEventListener( “userInput”, textBoxDay )
textBoxDay.inputType = “number”
scrollView:insert( textBoxDay )
–forwardSlash
local forwardSlash = display.newImage( “forwardSlash.png” )
forwardSlash:translate( 105, 270 )
scrollView:insert( forwardSlash )
–textBoxMonth
local textBoxMonth = native.newTextField( 156, 270, 75, 40 )
textBoxMonth.size = 20
textBoxMonth:addEventListener( “userInput”, textBoxMonth )
textBoxMonth.inputType = “number”
scrollView:insert( textBoxMonth )
–forwardSlash
local forwardSlash = display.newImage( “forwardSlash.png” )
forwardSlash:translate( 207, 270 )
scrollView:insert( forwardSlash )
–textBoxYear
local textBoxYear = native.newTextField( 258, 270, 75, 40 )
textBoxYear.size = 20
textBoxYear:addEventListener( “userInput”, textBoxYear )
textBoxYear.inputType = “number”
scrollView:insert( textBoxYear )
–textTime
local textTime = display.newText(“Incident Time: (HH:MM)”,
175, 430, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textTime:setFillColor( 0, 0, 0 )
scrollView:insert( textTime )
–textBoxHour
local textBoxHour = native.newTextField( 156, 350, 75, 40 )
textBoxHour.size = 20
textBoxHour:addEventListener( “userInput”, textBoxHour )
textBoxHour.inputType = “number”
scrollView:insert( textBoxHour )
–semiColon
local semiColon = display.newImage( “semiColon.png” )
semiColon:translate( 105, 350 )
scrollView:insert( semiColon )
–textBoxMinute
local textBoxMinute = native.newTextField( 54, 350, 75, 40 )
textBoxMinute.size = 20
textBoxMinute:addEventListener( “userInput”, textBoxMinute )
textBoxMinute.inputType = “number”
scrollView:insert( textBoxMinute )
–textWasThis
local textWasThis = display.newText(“Was this an incident that caused harm?”,
212, 532, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textWasThis:setFillColor( 0, 0, 0 )
scrollView:insert( textWasThis )
–textEgPer
local textEgPer = display.newText(“eg personal harm or damage to property”,
212, 547, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 11 )
textEgPer:setFillColor( 0, 0, 0 )
scrollView:insert( textEgPer )
–checkbox1
local checkbox1 = widget.newSwitch
{
left = 10,
top = 410,
style = “checkbox”,
id = “checkbox1”,
}
scrollView:insert( checkbox1 )
–textWasThisA
local textWasThisA = display.newText(“Was this a Near Miss (No Harm)?”,
212, 590, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textWasThisA:setFillColor( 0, 0, 0 )
scrollView:insert( textWasThisA )
–checkbox2
local checkbox2 = widget.newSwitch
{
left = 10,
top = 460,
style = “checkbox”,
id = “checkbox2”,
}
scrollView:insert( checkbox2 )
–divider
local divider = display.newImage( “divider.png” )
divider:translate( 160, 515 )
scrollView:insert( divider )
–textWhoWas
local textWhoWas = display.newText(“Who was affected by or at risk by the incident?”,
172, 655, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 20 )
textWhoWas:setFillColor( 0, 0, 0 )
scrollView:insert( textWhoWas )
–textStaff
local textStaff = display.newText(“Staff”,
212, 720, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textStaff:setFillColor( 0, 0, 0 )
scrollView:insert( textStaff )
–checkbox3
local checkbox3 = widget.newSwitch
{
left = 10,
top = 590,
style = “checkbox”,
id = “checkbox3”,
}
scrollView:insert( checkbox3 )
–textStudent
local textStudent = display.newText(“Student”,
212, 770, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textStudent:setFillColor( 0, 0, 0 )
scrollView:insert( textStudent )
–checkbox4
local checkbox4 = widget.newSwitch
{
left = 10,
top = 640,
style = “checkbox”,
id = “checkbox4”,
}
scrollView:insert( checkbox4 )
–textPublic
local textPublic = display.newText(“Public/Visitor”,
212, 820, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textPublic:setFillColor( 0, 0, 0 )
scrollView:insert( textPublic )
–checkbox5
local checkbox5 = widget.newSwitch
{
left = 10,
top = 690,
style = “checkbox”,
id = “checkbox5”,
}
scrollView:insert( checkbox5 )
–textContractor
local textContractor = display.newText(“Contractor”,
212, 870, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textContractor:setFillColor( 0, 0, 0 )
scrollView:insert( textContractor )
–checkbox6
local checkbox6 = widget.newSwitch
{
left = 10,
top = 740,
style = “checkbox”,
id = “checkbox6”,
}
scrollView:insert( checkbox6 )
–Scene Group
sceneGroup:insert( scrollView )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
– Called when the scene is still off screen and is about to move on screen
elseif phase == “did” then
– Called when the scene is now on screen
–
– INSERT code here to make the scene come alive
– e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == “will” then
– Called when the scene is on screen and is about to move off screen
–
– INSERT code here to pause the scene
– e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == “did” then
– Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s “view” (sceneGroup)
–
– INSERT code here to cleanup the scene
– e.g. remove display objects, remove touch listeners, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
Thanks,
Matt. 