I am trying to get the native keyboard 2 display to work on one of my screens. I stripped away everything I didn’t want or thought I needed in the tutorial and build it and it looked fine on my device. I then want to move that coding to my app to make it work there. So basically I had my screen already set up I just need to move the code to my screen and make it work. I am now getting an error when I try to load that screen. I was not sure where I needed to post the coding to make it work properly. Could somebody tell me what I’m doing wrong?
The lines I add from the tutorial are Lines 10 - 12 and Lines 137 - 233
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file
local ui = require(“ui”)
local tHeight – forward reference
local physics = require (“physics”)
physics.start ()
local background = display.newImage (“blackbackground.png”)
background.x = 240
localGroup:insert(background)
–> This sets the background
local screen6 = display.newImage (“screen6.png”)
screen6.x = 240
localGroup:insert(screen6)
–> This sets Screen6
local house = display.newImage (“house.png”)
house.x = 45
house.y = 35
house.xScale = .5
house.yScale = .5
localGroup:insert(house)
–>This places the House
local function touchedHouse (event)
if (“ended” == event.phase) then
director:changeScene (“titlescreen”)
media.playEventSound( “click_x.caf” )
end
end
house:addEventListener (“touch”, touchedHouse)
local numberTwo = display.newImage (“numberTwo.png”)
numberTwo.x = 240
numberTwo.y = 145
numberTwo.xScale = .5
numberTwo.yScale = .5
localGroup:insert(numberTwo)
–>This places the number two
local numberThree = display.newImage (“numberThree.png”)
numberThree.x = 240
numberThree.y = 200
numberThree.xScale = .5
numberThree.yScale = .5
localGroup:insert(numberThree)
–>This places the number three
local numberFour = display.newImage (“numberFour.png”)
numberFour.x = 240
numberFour.y = 270
numberFour.xScale = .5
numberFour.yScale = .5
localGroup:insert(numberFour)
–>This places the number four
– Handlers for login dialog UI
local function onnumberTwo( event )
if ( “began” == event.phase ) then
– Note: this is the “keyboard appearing” event
– In some cases you may want to adjust the interface while the keyboard is open.
elseif ( “submitted” == event.phase ) then
– Automatically tab to password field if user clicks “Return” on iPhone keyboard (convenient!)
native.setKeyboardFocus( passwordField )
end
end
local function onnumberThree( event )
– Hide keyboard when the user clicks “Return” in this field
if ( “submitted” == event.phase ) then
native.setKeyboardFocus( nil )
end
end
numberTwo = native.newTextField( 50, 150, 220, 36, onNumberTwo )
numberTwo.font = native.newFont( native.systemFontBold, 24 )
numberTwo.text = “”
numberTwo:setTextColor( 51, 51, 122, 255 )
numberThree = native.newTextField( 50, 210, 220, 36, onNumberTwo )
numberThree.font = native.newFont( native.systemFontBold, 24 )
numberThree.text = “”
numberThree.isSecure = true
numberThree:setTextColor( 51, 51, 122, 255 )
local smallbrain = display.newImage (“smallbrain.png”)
smallbrain.x = 428
smallbrain.y = 280
smallbrain.xScale = .5
smallbrain.yScale = .5
localGroup:insert(smallbrain)
–>This places the brain
local function touchedSmallbrain (event)
if (“ended” == event.phase) then
director:changeScene (“screen7a”)
media.playEventSound( “click_x.caf” )
end
end
smallbrain:addEventListener (“touch”, touchedSmallbrain)
local backbutton = display.newImage (“backbutton.png”)
backbutton.x = 60
backbutton.y = 280
backbutton.xScale = .4
backbutton.yScale = .4
localGroup:insert(backbutton)
local function touchedBackbutton (event)
if (“ended” == event.phase) then
director:changeScene (“screen5”)
media.playEventSound( “click_x.caf” )
end
end
backbutton:addEventListener (“touch”, touchedBackbutton)
–>This places the backbutton
– General event handler for fields
– You could also assign different handlers for each textfield
local function fieldHandler( event )
if ( “began” == event.phase ) then
– This is the “keyboard has appeared” event
– In some cases you may want to adjust the interface when the keyboard appears.
elseif ( “ended” == event.phase ) then
– This event is called when the user stops editing a field: for example, when they touch a different field
elseif ( “submitted” == event.phase ) then
– This event occurs when the user presses the “return” key (if available) on the onscreen keyboard
– Hide keyboard
native.setKeyboardFocus( nil )
end
end
– Predefine local objects for use later
local defaultField, numberField, phoneField, urlField, emailField, passwordField
local fields = display.newGroup()
– *** Create native input textfields ***
– Note: currently this feature works in device builds or Xcode simulator builds only
– Note: currently this feature works in device builds only
local isAndroid = “Android” == system.getInfo(“platformName”)
local inputFontSize = 40
local inputFontHeight = 40
tHeight = 60
if isAndroid then
– Android text fields have more chrome. It’s either make them bigger, or make the font smaller.
– We’ll do both
inputFontSize = 40
inputFontHeight = 40
tHeight = 60
end
numberField = native.newTextField( 240, 145, 120, tHeight, fieldHandler )
numberField.font = native.newFont( native.systemFontBold, inputFontSize )
numberField.inputType = “number”
numberField = native.newTextField( 240, 200, 120, tHeight, fieldHandler )
numberField.font = native.newFont( native.systemFontBold, inputFontSize )
numberField.inputType = “number”
– Add fields to our new group
fields:insert(numberField)
________________________________________________________________
– Create a Background touch event
local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bkgd:setFillColor( 0, 0, 0, 0 ) – set Alpha = 0 so it doesn’t cover up our buttons/fields
– Tapping screen dismisses the keyboard
– Needed for the Number and Phone textFields since there is
– no return key to clear focus.
local listener = function( event )
– Hide keyboard
print(“tap pressed”)
native.setKeyboardFocus( nil )
end
– Determine if running on Corona Simulator
local isSimulator = “simulator” == system.getInfo(“environment”)
– Native Text Fields not supported on Simulator
if isSimulator then
msg = display.newText( “Native Text Fields not supported on Simulator!”, 0, 280, “Verdana-Bold”, 12 )
msg.x = display.contentWidth/2 – center title
msg:setTextColor( 255,255,0 )
end
– Add listener to background for user “tap”
bkgd:addEventListener( “tap”, listener )
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first comment
–REMOVE THE FOLLOWING LINE:
return localGroup
end[/lua] [import]uid: 72372 topic_id: 13427 reply_id: 313427[/import]