I’m trying to use the textfield for the first time in my app, but I’m wonder how exactly I would Have it do certain things for certain words that are typed? So basically if they typed next, it go to the next scene, or back or save and so on and so fourth. Is it possible to have it listen for certain words then respond how I would like it too? Thanks for any help!
Hi,
check this out:
https://docs.coronalabs.com/daily/api/library/native/newTextField.html
local defaultField local function textListener( event ) if ( event.phase == "began" ) then -- user begins editing defaultField print( event.text ) elseif ( event.phase == "ended" or event.phase == "submitted" ) then -- do something with defaultField text print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end -- Create text field defaultField = native.newTextField( 150, 150, 180, 30 ) defaultField:addEventListener( "userInput", textListener )
There you have a textField listener so when the user is typing you can check that in the “editing” phase:
if event.text == “my_secret_text” then composer.gotoScene( “myScene”) end
Best regards,
Tomas
SPRS88: I’d check out one of Corona’s sample projects to see how they do it. If you want you can also see how our app implements search using Corona SDK (tap the search icon in the top right of the main screen): https://play.google.com/store/apps/details?id=io.recent.personal.news
Hi,
check this out:
https://docs.coronalabs.com/daily/api/library/native/newTextField.html
local defaultField local function textListener( event ) if ( event.phase == "began" ) then -- user begins editing defaultField print( event.text ) elseif ( event.phase == "ended" or event.phase == "submitted" ) then -- do something with defaultField text print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end -- Create text field defaultField = native.newTextField( 150, 150, 180, 30 ) defaultField:addEventListener( "userInput", textListener )
There you have a textField listener so when the user is typing you can check that in the “editing” phase:
if event.text == “my_secret_text” then composer.gotoScene( “myScene”) end
Best regards,
Tomas
SPRS88: I’d check out one of Corona’s sample projects to see how they do it. If you want you can also see how our app implements search using Corona SDK (tap the search icon in the top right of the main screen): https://play.google.com/store/apps/details?id=io.recent.personal.news