I’m testing hgvyas123’s code in http://developer.coronalabs.com/forum/2011/07/12/textfield-limited-length on my Android device.
-- TextField Listener
local function fieldHandler( getObj )
-- Use Lua closure in order to access the TextField object
return function( event )
print( "TextField Object is: " .. tostring( getObj() ) )
if ( "began" == event.phase ) then
-- This is the "keyboard has appeared" event
function chknum()
defaultField.text = string.sub(defaultField.text,1,6)
end
Runtime:addEventListener("enterFrame",chknum)
elseif ( "ended" == event.phase ) then
-- This event is called when the user stops editing a field:
-- for example, when they touch a different field or keyboard focus goes away
print( "Text entered = " .. tostring( getObj().text ) ) -- display the text entered
elseif ( "submitted" == event.phase ) then
-- This event occurs when the user presses the "return" key
-- (if available) on the onscreen keyboard
-- Hide keyboard
Runtime:removeEventListener("enterFrame",chknum)
native.setKeyboardFocus( nil )
end
end -- "return function()"
end
-- Create our Text Field
defaultField = native.newTextField( 10, 30, 180, 30, fieldHandler( function() return defaultField end ) )
But, on line 13, that is, defaultField.text = string.sub(defaultField.text,1,6), program was frozen.
When I comment the line, program ran.
Please teach me resolutions!! [import]uid: 161206 topic_id: 28221 reply_id: 328221[/import]