Login link

I am creating an app and i am having a problem . I created a link to take me to the login page but when I click the link it doesn’t work . 

-- requires local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require("widget") -- background function scene:createScene(event) local screenGroup = self.view display.setDefault("background", 0, 3, 5) local icon = display.newImage("xx.png", 160, 100) screenGroup:insert(icon) local username = native.newTextField( 160, 230, 180, 30 ) username.placeholder = "Username" screenGroup:insert(username) local password = native.newTextField( 160, 270,180, 30 ) password.isSecure = true password.placeholder = "Password" screenGroup:insert(password) local email = native.newTextField( 160, 310, 180, 30 ) email.placeholder = "E-mail" screenGroup:insert(email) end -- Create the widget local Register = widget.newButton( { shape = "roundedRect", left = 70, top = 360, id = "Register", label = "Register", onEvent = handleButtonEvent } ) local loginLink = widget.newButton( { left = 70, top = 450, id = "Login", label = "Login here", onEvent = loginLink } ) local function handleButtonEvent( event ) if ( "ended" == event.phase ) then else end end local function loginLink( event ) if ( "began" == event.phase ) then storyboard.gotoScene("login", "fade", 200) end end function scene:enterScene(event) end function scene:exitScene(event) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene

The loginLink is suppose to take me to the login page but it doesn’t . I am not getting any errors it’s just not doing it’s job . Can someone help me ?

first you use the attribute loginlink twice which is not good, second you need to put your login link function above login link button. But still change the name variable of the function or widget

I changed it to this :

local button2 = widget.newButton( { left = 70, top = 450, id = "Login", label = "Login here", onEvent = loginLink } ) local function loginLink( event ) if ( "began" == event.phase ) then storyboard.gotoScene("login", "fade", 200) end end

But it’s still not working .

The storyboard is deprecated.

https://forums.coronalabs.com/topic/45041-is-it-true-that-storyboard-is-deprecated/

You should use composer. Read about it

https://docs.coronalabs.com/daily/api/library/composer/index.html 

https://docs.coronalabs.com/daily/guide/system/composer/index.html#TOC

Code below run on simulator. It works :slight_smile:

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local function handleButtonEvent( event )     if ( "ended" == event.phase ) then     else     end end local function loginLink( event ) print( "loginLink" .. event.phase )     if ( "began" == event.phase ) then          --composer.gotoScene("login", "fade", 200)     end end function scene:create(event)    local screenGroup = self.view         display.setDefault("background", 0, 3, 5)    local icon = display.newImage("xx.png", 160, 100)    screenGroup:insert(icon)    local username = native.newTextField( 160, 230, 180, 30 )    username.placeholder = "Username"    screenGroup:insert(username)    local password = native.newTextField( 160, 270,180, 30 )    password.isSecure = true    password.placeholder = "Password"    screenGroup:insert(password)    local email = native.newTextField( 160, 310, 180, 30 )    email.placeholder = "E-mail"    screenGroup:insert(email) end -- Create the widget  local Register = widget.newButton(     {         shape = "roundedRect",         left = 70,         top = 360,         id = "Register",         label = "Register",         onEvent = handleButtonEvent     } ) local  loginLink = widget.newButton(     {         left = 70,         top = 450,         id = "Login",         label = "Login here",         onEvent = loginLink     } ) function scene:show(event) end function scene:hide(event) end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

Hope this help :slight_smile:

but I rather use storyboard and someone on here told me that is what I can use so I prefer storyboard 

Try like this. As @scottrules44 suggested.

local function loginLink( event ) if ( "began" == event.phase ) then storyboard.gotoScene("login", "fade", 200) end end local button2 = widget.newButton( { left = 70, top = 450, id = "Login", label = "Login here", onEvent = loginLink } )

I have it just like that and when I click on it , my icon blinks but I don’t change scenes 

The reason you got this error is because of scoping. I said you need to move it in my post above.

https://youtu.be/2ATlcGP2zMY

We can not force you to use storyboard but you should know it no longer support all by corona. If corona changes a few things in thier core that affect storyboard you out of luck. Composer works with composer gui and has more features. All of the function are the same so storyboard.gotoScene is composer.gotoScene. Also it is easier to fix problems the fourms. I was used corona after storyboard so I only know a what is can read on migration guide.

Did this and it still doesn’t work 

Did you notice comment in code below or just copy/paste and run code?

local function loginLink( event ) print( "loginLink" .. event.phase ) &nbsp; &nbsp; if ( "began" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--composer.gotoScene("login", "fade", 200) \<-- &nbsp; &nbsp; end end

but try this 

main.lua

local composer = require( "composer" ) local scene = composer.newScene() composer.gotoScene("start", "fade", 200)

start.lua

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local Register local &nbsp;loginLink local function handleButtonEvent( event ) &nbsp; &nbsp; if ( "ended" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp;composer.gotoScene("login", "fade", 200) &nbsp; &nbsp; else &nbsp; &nbsp; end end local function loginLink( event ) print( "loginLink" .. event.phase ) &nbsp; &nbsp; if ( "began" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;composer.gotoScene("login", "fade", 200) &nbsp; &nbsp; end end function scene:create(event) &nbsp; &nbsp;local screenGroup = self.view&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--[[&nbsp; &nbsp;display.setDefault("background", 0, 3, 5) &nbsp; &nbsp;local icon = display.newImage("xx.png", 160, 100) &nbsp; &nbsp;screenGroup:insert(icon) &nbsp; &nbsp;local username = native.newTextField( 160, 230, 180, 30 ) &nbsp; &nbsp;username.placeholder = "Username" &nbsp; &nbsp;screenGroup:insert(username) &nbsp; &nbsp;local password = native.newTextField( 160, 270,180, 30 ) &nbsp; &nbsp;password.isSecure = true &nbsp; &nbsp;password.placeholder = "Password" &nbsp; &nbsp;screenGroup:insert(password) &nbsp; &nbsp;local email = native.newTextField( 160, 310, 180, 30 ) &nbsp; &nbsp;email.placeholder = "E-mail" &nbsp; &nbsp;screenGroup:insert(email) &nbsp; --]] &nbsp; &nbsp;-- Create the widget &nbsp;Register = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; shape = "roundedRect", &nbsp; &nbsp; &nbsp; &nbsp; left = 70, &nbsp; &nbsp; &nbsp; &nbsp; top = 360, &nbsp; &nbsp; &nbsp; &nbsp; id = "Register", &nbsp; &nbsp; &nbsp; &nbsp; label = "Register", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = handleButtonEvent &nbsp; &nbsp; } ) &nbsp; loginLink = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; left = 70, &nbsp; &nbsp; &nbsp; &nbsp; top = 450, &nbsp; &nbsp; &nbsp; &nbsp; id = "Login", &nbsp; &nbsp; &nbsp; &nbsp; label = "Login here", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = loginLink &nbsp; &nbsp; } ) screenGroup:insert(Register) screenGroup:insert(loginLink) end function scene:show(event) end function scene:hide(event) end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

It work on my lap :slight_smile:

first you use the attribute loginlink twice which is not good, second you need to put your login link function above login link button. But still change the name variable of the function or widget

I changed it to this :

local button2 = widget.newButton( { left = 70, top = 450, id = "Login", label = "Login here", onEvent = loginLink } ) local function loginLink( event ) if ( "began" == event.phase ) then storyboard.gotoScene("login", "fade", 200) end end

But it’s still not working .

The storyboard is deprecated.

https://forums.coronalabs.com/topic/45041-is-it-true-that-storyboard-is-deprecated/

You should use composer. Read about it

https://docs.coronalabs.com/daily/api/library/composer/index.html 

https://docs.coronalabs.com/daily/guide/system/composer/index.html#TOC

Code below run on simulator. It works :slight_smile:

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local function handleButtonEvent( event ) &nbsp; &nbsp; if ( "ended" == event.phase ) then &nbsp; &nbsp; else &nbsp; &nbsp; end end local function loginLink( event ) print( "loginLink" .. event.phase ) &nbsp; &nbsp; if ( "began" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--composer.gotoScene("login", "fade", 200) &nbsp; &nbsp; end end function scene:create(event) &nbsp; &nbsp;local screenGroup = self.view&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;display.setDefault("background", 0, 3, 5) &nbsp; &nbsp;local icon = display.newImage("xx.png", 160, 100) &nbsp; &nbsp;screenGroup:insert(icon) &nbsp; &nbsp;local username = native.newTextField( 160, 230, 180, 30 ) &nbsp; &nbsp;username.placeholder = "Username" &nbsp; &nbsp;screenGroup:insert(username) &nbsp; &nbsp;local password = native.newTextField( 160, 270,180, 30 ) &nbsp; &nbsp;password.isSecure = true &nbsp; &nbsp;password.placeholder = "Password" &nbsp; &nbsp;screenGroup:insert(password) &nbsp; &nbsp;local email = native.newTextField( 160, 310, 180, 30 ) &nbsp; &nbsp;email.placeholder = "E-mail" &nbsp; &nbsp;screenGroup:insert(email) end -- Create the widget &nbsp;local Register = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; shape = "roundedRect", &nbsp; &nbsp; &nbsp; &nbsp; left = 70, &nbsp; &nbsp; &nbsp; &nbsp; top = 360, &nbsp; &nbsp; &nbsp; &nbsp; id = "Register", &nbsp; &nbsp; &nbsp; &nbsp; label = "Register", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = handleButtonEvent &nbsp; &nbsp; } ) local &nbsp;loginLink = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; left = 70, &nbsp; &nbsp; &nbsp; &nbsp; top = 450, &nbsp; &nbsp; &nbsp; &nbsp; id = "Login", &nbsp; &nbsp; &nbsp; &nbsp; label = "Login here", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = loginLink &nbsp; &nbsp; } ) function scene:show(event) end function scene:hide(event) end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

Hope this help :slight_smile:

but I rather use storyboard and someone on here told me that is what I can use so I prefer storyboard 

Try like this. As @scottrules44 suggested.

local&nbsp;function&nbsp;loginLink(&nbsp;event&nbsp;) if&nbsp;(&nbsp;"began"&nbsp;==&nbsp;event.phase&nbsp;)&nbsp;then storyboard.gotoScene("login",&nbsp;"fade",&nbsp;200) end end local button2 = widget.newButton( { left = 70, top = 450, id = "Login", label = "Login here", onEvent = loginLink } )

I have it just like that and when I click on it , my icon blinks but I don’t change scenes 

The reason you got this error is because of scoping. I said you need to move it in my post above.

https://youtu.be/2ATlcGP2zMY

We can not force you to use storyboard but you should know it no longer support all by corona. If corona changes a few things in thier core that affect storyboard you out of luck. Composer works with composer gui and has more features. All of the function are the same so storyboard.gotoScene is composer.gotoScene. Also it is easier to fix problems the fourms. I was used corona after storyboard so I only know a what is can read on migration guide.

Did this and it still doesn’t work 

Did you notice comment in code below or just copy/paste and run code?

local function loginLink( event ) print( "loginLink" .. event.phase ) &nbsp; &nbsp; if ( "began" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--composer.gotoScene("login", "fade", 200) \<-- &nbsp; &nbsp; end end

but try this 

main.lua

local composer = require( "composer" ) local scene = composer.newScene() composer.gotoScene("start", "fade", 200)

start.lua

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local Register local &nbsp;loginLink local function handleButtonEvent( event ) &nbsp; &nbsp; if ( "ended" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp;composer.gotoScene("login", "fade", 200) &nbsp; &nbsp; else &nbsp; &nbsp; end end local function loginLink( event ) print( "loginLink" .. event.phase ) &nbsp; &nbsp; if ( "began" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;composer.gotoScene("login", "fade", 200) &nbsp; &nbsp; end end function scene:create(event) &nbsp; &nbsp;local screenGroup = self.view&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--[[&nbsp; &nbsp;display.setDefault("background", 0, 3, 5) &nbsp; &nbsp;local icon = display.newImage("xx.png", 160, 100) &nbsp; &nbsp;screenGroup:insert(icon) &nbsp; &nbsp;local username = native.newTextField( 160, 230, 180, 30 ) &nbsp; &nbsp;username.placeholder = "Username" &nbsp; &nbsp;screenGroup:insert(username) &nbsp; &nbsp;local password = native.newTextField( 160, 270,180, 30 ) &nbsp; &nbsp;password.isSecure = true &nbsp; &nbsp;password.placeholder = "Password" &nbsp; &nbsp;screenGroup:insert(password) &nbsp; &nbsp;local email = native.newTextField( 160, 310, 180, 30 ) &nbsp; &nbsp;email.placeholder = "E-mail" &nbsp; &nbsp;screenGroup:insert(email) &nbsp; --]] &nbsp; &nbsp;-- Create the widget &nbsp;Register = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; shape = "roundedRect", &nbsp; &nbsp; &nbsp; &nbsp; left = 70, &nbsp; &nbsp; &nbsp; &nbsp; top = 360, &nbsp; &nbsp; &nbsp; &nbsp; id = "Register", &nbsp; &nbsp; &nbsp; &nbsp; label = "Register", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = handleButtonEvent &nbsp; &nbsp; } ) &nbsp; loginLink = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; left = 70, &nbsp; &nbsp; &nbsp; &nbsp; top = 450, &nbsp; &nbsp; &nbsp; &nbsp; id = "Login", &nbsp; &nbsp; &nbsp; &nbsp; label = "Login here", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = loginLink &nbsp; &nbsp; } ) screenGroup:insert(Register) screenGroup:insert(loginLink) end function scene:show(event) end function scene:hide(event) end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

It work on my lap :slight_smile: