Below is a code for a login page and I’m not sure why the username and password text box moving to the next scene when changed. I know it will work if I could use scene group but unfortunately, you can’t use native with scene group. Can someone help me please??
–Login Screen.Lua
–library
local composer = require (“composer”)
local scene = composer.newScene ()
local w, h = display.contentWidth, display.contentHeight
local w2, h2 = display.contentCenterX, display.contentCenterY
local mybutton, Error, signupText, pwdRecovery, username1, password1, username, password
–Background Color
display.setDefault( “background”, 0.8, 0.8, 0.8 )
local function textListener (event)
local textboxEdited = event.target.name
if ( event.phase == “began” ) then
elseif ( event.phase == “ended” or event.phase == “submitted” ) then
elseif (event.phase == “editing” ) then
if ( textboxEdited == “UserLogin” ) then
mylogin = event.target.text
print (mylogin)
end
if ( textboxEdited == “UserPassword”) then
pass = event.target.text
print(pass)
end
end
end
local function keyboardListener ( event )
native.setKeyboardFocus(nil)
end
local function goToHome ( event )
if event.phase == “began” then
composer.gotoScene (“Home”, “fade”, 400)
end
end
–scene:create()
function scene:create (event)
local sceneGroup = self.view
local login = { type = “image”, filename = “Login.jpg”}
mybutton = display.newRect(w2, h *0.68, 95, 40)
mybutton.fill = login
sceneGroup:insert (mybutton)
–mybutton.touch = goToHome
Error = display.newText (“Invlaid Username or Password”, w2, h * 0.95, Arial, 15)
Error:setFillColor (1,0,0)
Error.isVisible = false
sceneGroup:insert(Error)
–Sign Up Text
signupText = display.newText (“Sign Up”, w2, h * 0.9, Arial, 15)
signupText:setFillColor(0,0,0)
sceneGroup:insert(signupText)
–Password Recovery Text
local pwdRecovery = display.newText(“Forgot Password?”, w2, h * 0.95, Arial, 15)
pwdRecovery:setFillColor(0,0,0)
sceneGroup:insert(pwdRecovery)
end
–scene:show()
function scene:show(event)
local sceneGroup = self.view
local phase = event.phase
if ( phase == “did” ) then
composer.removeScene( “Splash Screen” )
mybutton:addEventListener(“touch”, goToHome )
–Username TextBox
username = native.newTextField (w2, h * 0.43, 200, 30)
username.inputType = “default”
username.name = " UserLogin"
–Password TextBox
password = native.newTextField (w2, h * 0.57, 200, 30)
password.inputType = “default”
password.name = “UserPassword”
–username
local userText = display.newText (“Username”, w2, h * 0.38, Arial, 20 )
userText:setFillColor (0,0,0)
sceneGroup:insert(userText)
–password
local pwdText = display.newText (“Password”, w2, h * 0.52, Arial, 20 )
pwdText:setFillColor (0,0,0)
sceneGroup:insert(pwdText)
end
end
–scene:hide()
function scene:hide(event)
if (phase == “will” ) then
end
end
–scene:distroy()
function scene:distroy(event)
local sceneGroup = self.view
end
–listener setup
scene:addEventListener(“create”, scene)
scene:addEventListener(“show”, scene)
scene:addEventListener(“hide”, scene)
scene:addEventListener(“distroy”, scene)
return scene