Trouble with fieldHandler

HI,

Am having big trouble using the handler below.

Want to include details in the ‘Began’ phase to shift the fields position before I enter the text, nothing I try seems to work. Any ideas?

local function fieldHandler( event )

if ( “began” == event.phase ) then

textMode = true

elseif ( “ended” == event.phase ) then

elseif ( “submitted” == event.phase ) then

– Hide keyboard
native.setKeyboardFocus( nil )
textMode = false
end
end

Thanks

Richard [import]uid: 7830 topic_id: 9532 reply_id: 309532[/import]

Please provide examples of how you are attaching the field handler and what sort of behavior constitutes “trouble”…what are you seeing in the Xcode simulator? [import]uid: 6175 topic_id: 9532 reply_id: 34845[/import]

Thanks for the reply.

I have the Loop shown below:

for i=1,11 do
player_text[i]= native.newTextField(70, 100+(y*i), 280, 30, fieldHandler )
player_text[i]:setReferencePoint(display.CenterLeftReferencePoint)
player_text[i].isVisible = true
end

This means that some of the fields are below the keyboard when it pos up. What I want to do is as the keyboard appears, the required Field changes its position to the top of the screen so that it can be seen, I have tried using things such as.
event.target.x
But it will not locate the field that has been selected.

Thanks for any help you can give… [import]uid: 7830 topic_id: 9532 reply_id: 34846[/import]

yeah, you don’t get target and there is a bug preventing use of a table listener, so you have to use a closure like this:

[lua] local natFld
local lfc = function(l_event)
natFld:userInput(l_event)
end
natFld = native.newTextField(fieldX,startY,fieldWidth,rowHeight, lfc)
natFld.origY = startY – remember for scrolling
natFld.userInput = fieldHandler[/lua]

The code order above is VERY important.

So when “fieldHandler” gets called, it’s only passed l_event, but the closure passes the whole object and so you can use “self.x” or any other attribute.

So in your code above, param #1 must be self like this:

local function fieldHandler(self, event ) [import]uid: 6175 topic_id: 9532 reply_id: 34859[/import]