Hi guys i'm a newbie in corona and i have a problem with input fields that i can't rid off

The code:

–[[ DEBUGGING MODE
print("Data: "…data)
print("HTTP Status: "…httpStatus)
httpResponseHeaders=json.encode(httpResponseHeaders)
print("HTTP Response Headers: "…httpResponseHeaders)
print("HTTP Response Status Line: "…httpResponseStatusLine)
–]]

local storyboard = require “storyboard”
local movieclip     = require “movieclip”
local widget      = require “widget”
local http          = require “socket.http”
local crypto      = require “crypto”
local ltn12      = require “ltn12”
local url          = require “socket.url”
local json       = require “json”

local scene = storyboard.newScene()
local LoggedIn,PasswordText,UserNameText,Password,UserName,fields

 – Request url for retrieving data
local data,httpStatus,httpResponseHeaders,httpResponseStatusLine=http.request(“http://www.BurtonsMediaGroup.com/myMovies.php”)
local table=json.decode(data)

local myTextField

– Called when the scene’s view does not exist:
function scene:createScene( event )
    local group = self.view

    local function onHomeView( event )
        group = scene.view
        --storyboard.purgeScene(“viewHome”)
            --UserName:removeSelf()
        –     UserName = nil
        – storyboard.gotoScene( “viewHome” , {
        –                                     effect = “fade”,
        –                                     time = 100,
        –                                         params =
        –                                             {
        –                                                 ok = LoggedIn
        –                                             }
        –                                      })
        – storyboard.myTabBar = tabBar

    end

end

– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
    local group = self.view
    fields = display.newGroup()

    local LoginUrl = “http://crmstefan.zz.mu/corona.php”    

    local logo = display.newImage( “images/logo.png”, display.contentHeight*0.01, display.contentHeight*0.04 )
    local myria_logo = display.newImage( “images/myria.png”, display.contentWidth-205, display.contentHeight*0.04 )

    group:insert(logo)
    group:insert(myria_logo)

    local myAnim = movieclip.newAnim({ “loading1.png”, “loading1.png”, “loading1.png”, “loading1.png”, “loading2.png”, “loading2.png”, “loading2.png”, “loading2.png”, “loading3.png”, “loading3.png”, “loading3.png”, “loading3.png”, “loading4.png”, “loading4.png”, “loading4.png”, “loading4.png”, “loading5.png”, “loading5.png”, “loading5.png”, “loading5.png”, “loading6.png”, “loading6.png”, “loading6.png”, “loading6.png”, “loading7.png”, “loading7.png”, “loading7.png”, “loading7.png”, “loading8.png”, “loading8.png”, “loading8.png”, “loading8.png” })
    myAnim.x = display.contentWidth/2;
    myAnim.y = display.contentHeight/2+20
    myAnim:play{ startFrame=1, endFrame=15, loop = 1, remove=true}

    local scrollView = widget.newScrollView
    {
        top = 0,
        left = 0,
        width = 0,
        height = 0,
        scrollHeight = 0,
    }

    local function UsernameListener( event )
       if “submitted” == event.phase then
            UserName = event.target.text
        elseif ( “ended” == event.phase ) then
            native.setKeyboardFocus( nil )
        elseif ( “submitted” == event.phase ) then
            native.setKeyboardFocus( Password )
        end
    end

    local function PasswordListener( event )
       if “submitted” == event.phase then
            Password = event.target.text
        end
    end

    local function onSubmit( event )

        if (Password) then

            local ParseData =
            {
                [“username”] = “alex”,
                [“password”] = “pass”
            }
            
            – Elements of ParseData to check from Simulator
            –     [“username”] = “alex”,
            –     [“password”] = “pass”
            —  For production
            –     [“username”] = UserName,
            –     [“password”] = Password

            local ParseData = json.encode (ParseData)

            local json = {}
            json.api_key = “6_192116334”
            json.ver = 1
            json.commands_hash = crypto.digest(crypto.md5, ParseData)
            
            local post = “data=”…url.escape(ParseData)
            local response = {}
            
            local r, c, h = http.request {
                url = LoginUrl,
                method = “POST”,
                headers = {
                    [“content-length”] = #post,
                    [“Content-Type”] =  “application/x-www-form-urlencoded”
                },
                source = ltn12.source.string(post),
                sink = ltn12.sink.table(response)
            }

            data_ok = tonumber(response[1])

            if (data_ok == 1) then
                LoggedIn = 1
                onHomeView()

            else
                 LoggedIn = 0

                local text = display.newText(LoggedIn, 0, 0, native.systemFont, 24)
                   text:setTextColor(0,0,0)
                   text.x = display.contentWidth/2
                   text.y = (display.contentHeight/3)+100
                   text.size = 24
                   group:insert(text)
                
            end    

        print (response[1])
        end-- end

    end

      myTextField = native.newTextField(0, 0, 200, 50)
    myTextField:addEventListener(“userInput”, UsernameListener)

– Begin UserName input
    UserNameText = display.newText(“Username”, 0, 0, native.systemFont, 26)
               UserNameText:setTextColor(0,0,0)
               UserNameText.x = (display.contentWidth/3)-60
               UserNameText.y = (display.contentHeight/4)+40
               UserNameText.size = 24
               group:insert(UserNameText)

    UserName = native.newTextField( display.contentWidth/3, display.contentHeight/4, 210, 70 )
    UserName:addEventListener( “userInput”, UsernameListener )

– End of UserName input

– Begin Password input
    PasswordText = display.newText(“Password”, 0, 0, native.systemFont, 26)
               PasswordText:setTextColor(0,0,0)
               PasswordText.x = (display.contentWidth/3)-60
               PasswordText.y = (display.contentHeight/3)+40
               PasswordText.size = 24
               group:insert(PasswordText)

    Password = native.newTextField( display.contentWidth/3, display.contentHeight/3, 210, 70 )
    Password.font = native.newFont( native.systemFontBold, inputFontSize )
    Password:addEventListener( “userInput”, PasswordListener )
    Password.isSecure = true
    
    fields:insert(UserName)
    fields:insert(Password)
– End of Password input

    local submit = widget.newButton {

        label = “Log In”,
        font = default,
        fontSize = 24,
        width = 130,
        height = 50,
        onPress=onSubmit,

    }

    submit.x = display.contentWidth/2
    submit.y = display.contentHeight/2-0.102
    submit:addEventListener( “touch”, onSubmit )
    group:insert(submit)
    
    

end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
    local group = self.view

    --display.remove(fields)
    – if Password then
        
    –     --fields:remove( UserName )
    –     Password:removeSelf()
    –     Password = nil
    – end
    
    if UserName then
        – fields:remove( UserName )
        UserName:removeSelf()
        UserName = nil
    end

    native.setKeyboardFocus(nil)

    display.remove(group)
    display.remove(scrollView)
    if myTextField then
        myTextField:removeSelf()
        myTextField = nil
    end

    
    
    – INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
    local group = self.view
    
    – INSERT code here (e.g. remove listeners, remove widgets, save state variables, 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 whenever 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

If i move to another scene, the input field remains on the screen, i’ve tried all the possibilities that i’ve found but none of them seems to work right
 

Sorry for my bad english !

Thanks !

Your code is a little hard to read, next time please place it between in code tags (see the <> in icon bar).  Are you adding your text fields to group?  

Sorry, next time i will place my code inside the tags !

No, JonPM, i didn’t, in fact i’ve tried also with groups, but i’ve read that groups doesn’t works with native.newTextField.

My code looks like this:

--[[DEBUGGING MODE print("Data: "..data) print("HTTP Status: "..httpStatus) httpResponseHeaders=json.encode(httpResponseHeaders) print("HTTP Response Headers: "..httpResponseHeaders) print("HTTP Response Status Line: "..httpResponseStatusLine) --]] local storyboard = require "storyboard" local movieclip = require "movieclip" local widget = require "widget" local http = require "socket.http" local crypto = require "crypto" local ltn12 = require "ltn12" local url = require "socket.url" local json = require "json" local scene = storyboard.newScene() local LoggedIn,PasswordText,UserNameText,Password,UserName,fields -- Request url for retrieving data local data,httpStatus,httpResponseHeaders,httpResponseStatusLine=http.request("http://www.BurtonsMediaGroup.com/myMovies.php") local table=json.decode(data) local function onHomeView( event ) group = scene.view storyboard.purgeScene("viewHome") storyboard.gotoScene( "viewHome" , { effect = "fade", time = 100, params = { ok = LoggedIn } }) storyboard.myTabBar = tabBar end -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view fields = display.newGroup() local LoginUrl = "http://crmstefan.zz.mu/corona.php" local logo = display.newImage( "images/logo.png", display.contentHeight\*0.01, display.contentHeight\*0.04 ) local myria\_logo = display.newImage( "images/myria.png", display.contentWidth-205, display.contentHeight\*0.04 ) group:insert(logo) group:insert(myria\_logo) local myAnim = movieclip.newAnim({ "loading1.png", "loading1.png", "loading1.png", "loading1.png", "loading2.png", "loading2.png", "loading2.png", "loading2.png", "loading3.png", "loading3.png", "loading3.png", "loading3.png", "loading4.png", "loading4.png", "loading4.png", "loading4.png", "loading5.png", "loading5.png", "loading5.png", "loading5.png", "loading6.png", "loading6.png", "loading6.png", "loading6.png", "loading7.png", "loading7.png", "loading7.png", "loading7.png", "loading8.png", "loading8.png", "loading8.png", "loading8.png" }) myAnim.x = display.contentWidth/2; myAnim.y = display.contentHeight/2+20 myAnim:play{ startFrame=1, endFrame=15, loop = 1, remove=true} local scrollView = widget.newScrollView { top = 0, left = 0, width = 0, height = 0, scrollHeight = 0, } local function UsernameListener( event ) if "submitted" == event.phase then UserName = event.target.text elseif ( "ended" == event.phase ) then native.setKeyboardFocus( nil ) elseif ( "submitted" == event.phase ) then native.setKeyboardFocus( Password ) end end local function PasswordListener( event ) if "submitted" == event.phase then Password = event.target.text end end local function onSubmit( event ) if (Password) then local ParseData = { ["username"] = "alex", ["password"] = "pass" } -- Elements of ParseData to check from Simulator -- ["username"] = "alex", -- ["password"] = "pass" --- For production -- ["username"] = UserName, -- ["password"] = Password local ParseData = json.encode (ParseData) local json = {} json.api\_key = "6\_192116334" json.ver = 1 json.commands\_hash = crypto.digest(crypto.md5, ParseData) local post = "data="..url.escape(ParseData) local response = {} local r, c, h = http.request { url = LoginUrl, method = "POST", headers = { ["content-length"] = #post, ["Content-Type"] = "application/x-www-form-urlencoded" }, source = ltn12.source.string(post), sink = ltn12.sink.table(response) } data\_ok = tonumber(response[1]) if (data\_ok == 1) then LoggedIn = 1 onHomeView() else LoggedIn = 0 local text = display.newText(LoggedIn, 0, 0, native.systemFont, 24) text:setTextColor(0,0,0) text.x = display.contentWidth/2 text.y = (display.contentHeight/3)+100 text.size = 24 group:insert(text) end print (response[1]) end-- end end -- Begin UserName input UserNameText = display.newText("Username", 0, 0, native.systemFont, 26) UserNameText:setTextColor(0,0,0) UserNameText.x = (display.contentWidth/3)-60 UserNameText.y = (display.contentHeight/4)+40 UserNameText.size = 24 group:insert(UserNameText) UserName = native.newTextField( display.contentWidth/3, display.contentHeight/4, 210, 70 ) UserName:addEventListener( "userInput", UsernameListener ) -- End of UserName input -- Begin Password input PasswordText = display.newText("Password", 0, 0, native.systemFont, 26) PasswordText:setTextColor(0,0,0) PasswordText.x = (display.contentWidth/3)-60 PasswordText.y = (display.contentHeight/3)+40 PasswordText.size = 24 group:insert(PasswordText) Password = native.newTextField( display.contentWidth/3, display.contentHeight/3, 210, 70 ) Password.font = native.newFont( native.systemFontBold, inputFontSize ) Password:addEventListener( "userInput", PasswordListener ) Password.isSecure = true -- End of Password input local submit = widget.newButton { label = "Log In", font = default, fontSize = 24, width = 130, height = 50, onPress=onSubmit, } submit.x = display.contentWidth/2 submit.y = display.contentHeight/2-0.102 submit:addEventListener( "touch", onSubmit ) group:insert(submit) fields:insert(UserName) fields:insert(Password) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view display.remove(fields) if Password then --fields:remove( UserName ) Password:removeSelf() Password = nil end display.remove(group) display.remove(scrollView) -- if UserName then -- fields:remove( UserName ) -- UserName:removeSelf() -- UserName = nil -- end native.setKeyboardFocus(nil) -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, 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 whenever 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 &nbsp;

And there are the lines that i fight with…

local LoggedIn,PasswordText,UserNameText,Password,UserName,fields .................. -- Begin UserName input UserNameText = display.newText("Username", 0, 0, native.systemFont, 26) UserNameText:setTextColor(0,0,0) UserNameText.x = (display.contentWidth/3)-60 UserNameText.y = (display.contentHeight/4)+40 UserNameText.size = 24 group:insert(UserNameText) UserName = native.newTextField( display.contentWidth/3, display.contentHeight/4, 210, 70 ) UserName:addEventListener( "userInput", UsernameListener ) -- End of UserName input -- Begin Password input PasswordText = display.newText("Password", 0, 0, native.systemFont, 26) PasswordText:setTextColor(0,0,0) PasswordText.x = (display.contentWidth/3)-60 PasswordText.y = (display.contentHeight/3)+40 PasswordText.size = 24 group:insert(PasswordText) Password = native.newTextField( display.contentWidth/3, display.contentHeight/3, 210, 70 ) Password.font = native.newFont( native.systemFontBold, inputFontSize ) Password:addEventListener( "userInput", PasswordListener ) Password.isSecure = true -- End of Password input display.remove(fields) if Password then Password:removeSelf() Password = nil end 

Thanks, for reading !

Your code is a little hard to read, next time please place it between in code tags (see the <> in icon bar).  Are you adding your text fields to group?  

Sorry, next time i will place my code inside the tags !

No, JonPM, i didn’t, in fact i’ve tried also with groups, but i’ve read that groups doesn’t works with native.newTextField.

My code looks like this:

--[[DEBUGGING MODE print("Data: "..data) print("HTTP Status: "..httpStatus) httpResponseHeaders=json.encode(httpResponseHeaders) print("HTTP Response Headers: "..httpResponseHeaders) print("HTTP Response Status Line: "..httpResponseStatusLine) --]] local storyboard = require "storyboard" local movieclip = require "movieclip" local widget = require "widget" local http = require "socket.http" local crypto = require "crypto" local ltn12 = require "ltn12" local url = require "socket.url" local json = require "json" local scene = storyboard.newScene() local LoggedIn,PasswordText,UserNameText,Password,UserName,fields -- Request url for retrieving data local data,httpStatus,httpResponseHeaders,httpResponseStatusLine=http.request("http://www.BurtonsMediaGroup.com/myMovies.php") local table=json.decode(data) local function onHomeView( event ) group = scene.view storyboard.purgeScene("viewHome") storyboard.gotoScene( "viewHome" , { effect = "fade", time = 100, params = { ok = LoggedIn } }) storyboard.myTabBar = tabBar end -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view fields = display.newGroup() local LoginUrl = "http://crmstefan.zz.mu/corona.php" local logo = display.newImage( "images/logo.png", display.contentHeight\*0.01, display.contentHeight\*0.04 ) local myria\_logo = display.newImage( "images/myria.png", display.contentWidth-205, display.contentHeight\*0.04 ) group:insert(logo) group:insert(myria\_logo) local myAnim = movieclip.newAnim({ "loading1.png", "loading1.png", "loading1.png", "loading1.png", "loading2.png", "loading2.png", "loading2.png", "loading2.png", "loading3.png", "loading3.png", "loading3.png", "loading3.png", "loading4.png", "loading4.png", "loading4.png", "loading4.png", "loading5.png", "loading5.png", "loading5.png", "loading5.png", "loading6.png", "loading6.png", "loading6.png", "loading6.png", "loading7.png", "loading7.png", "loading7.png", "loading7.png", "loading8.png", "loading8.png", "loading8.png", "loading8.png" }) myAnim.x = display.contentWidth/2; myAnim.y = display.contentHeight/2+20 myAnim:play{ startFrame=1, endFrame=15, loop = 1, remove=true} local scrollView = widget.newScrollView { top = 0, left = 0, width = 0, height = 0, scrollHeight = 0, } local function UsernameListener( event ) if "submitted" == event.phase then UserName = event.target.text elseif ( "ended" == event.phase ) then native.setKeyboardFocus( nil ) elseif ( "submitted" == event.phase ) then native.setKeyboardFocus( Password ) end end local function PasswordListener( event ) if "submitted" == event.phase then Password = event.target.text end end local function onSubmit( event ) if (Password) then local ParseData = { ["username"] = "alex", ["password"] = "pass" } -- Elements of ParseData to check from Simulator -- ["username"] = "alex", -- ["password"] = "pass" --- For production -- ["username"] = UserName, -- ["password"] = Password local ParseData = json.encode (ParseData) local json = {} json.api\_key = "6\_192116334" json.ver = 1 json.commands\_hash = crypto.digest(crypto.md5, ParseData) local post = "data="..url.escape(ParseData) local response = {} local r, c, h = http.request { url = LoginUrl, method = "POST", headers = { ["content-length"] = #post, ["Content-Type"] = "application/x-www-form-urlencoded" }, source = ltn12.source.string(post), sink = ltn12.sink.table(response) } data\_ok = tonumber(response[1]) if (data\_ok == 1) then LoggedIn = 1 onHomeView() else LoggedIn = 0 local text = display.newText(LoggedIn, 0, 0, native.systemFont, 24) text:setTextColor(0,0,0) text.x = display.contentWidth/2 text.y = (display.contentHeight/3)+100 text.size = 24 group:insert(text) end print (response[1]) end-- end end -- Begin UserName input UserNameText = display.newText("Username", 0, 0, native.systemFont, 26) UserNameText:setTextColor(0,0,0) UserNameText.x = (display.contentWidth/3)-60 UserNameText.y = (display.contentHeight/4)+40 UserNameText.size = 24 group:insert(UserNameText) UserName = native.newTextField( display.contentWidth/3, display.contentHeight/4, 210, 70 ) UserName:addEventListener( "userInput", UsernameListener ) -- End of UserName input -- Begin Password input PasswordText = display.newText("Password", 0, 0, native.systemFont, 26) PasswordText:setTextColor(0,0,0) PasswordText.x = (display.contentWidth/3)-60 PasswordText.y = (display.contentHeight/3)+40 PasswordText.size = 24 group:insert(PasswordText) Password = native.newTextField( display.contentWidth/3, display.contentHeight/3, 210, 70 ) Password.font = native.newFont( native.systemFontBold, inputFontSize ) Password:addEventListener( "userInput", PasswordListener ) Password.isSecure = true -- End of Password input local submit = widget.newButton { label = "Log In", font = default, fontSize = 24, width = 130, height = 50, onPress=onSubmit, } submit.x = display.contentWidth/2 submit.y = display.contentHeight/2-0.102 submit:addEventListener( "touch", onSubmit ) group:insert(submit) fields:insert(UserName) fields:insert(Password) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view display.remove(fields) if Password then --fields:remove( UserName ) Password:removeSelf() Password = nil end display.remove(group) display.remove(scrollView) -- if UserName then -- fields:remove( UserName ) -- UserName:removeSelf() -- UserName = nil -- end native.setKeyboardFocus(nil) -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, 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 whenever 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 &nbsp;

And there are the lines that i fight with…

local LoggedIn,PasswordText,UserNameText,Password,UserName,fields .................. -- Begin UserName input UserNameText = display.newText("Username", 0, 0, native.systemFont, 26) UserNameText:setTextColor(0,0,0) UserNameText.x = (display.contentWidth/3)-60 UserNameText.y = (display.contentHeight/4)+40 UserNameText.size = 24 group:insert(UserNameText) UserName = native.newTextField( display.contentWidth/3, display.contentHeight/4, 210, 70 ) UserName:addEventListener( "userInput", UsernameListener ) -- End of UserName input -- Begin Password input PasswordText = display.newText("Password", 0, 0, native.systemFont, 26) PasswordText:setTextColor(0,0,0) PasswordText.x = (display.contentWidth/3)-60 PasswordText.y = (display.contentHeight/3)+40 PasswordText.size = 24 group:insert(PasswordText) Password = native.newTextField( display.contentWidth/3, display.contentHeight/3, 210, 70 ) Password.font = native.newFont( native.systemFontBold, inputFontSize ) Password:addEventListener( "userInput", PasswordListener ) Password.isSecure = true -- End of Password input display.remove(fields) if Password then Password:removeSelf() Password = nil end 

Thanks, for reading !