Advertisement
lavalevel

error in: local listener = function(event)

Jan 26th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1.     local ui = require("ui")
  2.     -------------------------------------------
  3.     -- General event handler for fields
  4.     -------------------------------------------
  5.     -- You could also assign different handlers for each textfield
  6.     local function fieldHandler( event )
  7.  
  8.         if ( "began" == event.phase ) then
  9.             -- This is the "keyboard has appeared" event
  10.             -- In some cases you may want to adjust the interface when the keyboard appears.
  11.        
  12.         elseif ( "ended" == event.phase ) then
  13.             -- This event is called when the user stops editing a field: for example, when they touch a different field
  14.        
  15.         elseif ( "submitted" == event.phase ) then
  16.             -- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard
  17.         -- Hide keyboard
  18.             native.setKeyboardFocus( nil )
  19.         end
  20.     end
  21.     -- Predefine local objects for use later
  22.     local defaultField
  23.     local fields = display.newGroup()
  24.  
  25.     local isAndroid = "Android" == system.getInfo("platformName")
  26.     local inputFontSize = 18
  27.     local inputFontHeight = 30
  28.     if isAndroid then
  29.         -- Android text fields have more chrome. It's either make them bigger, or make the font smaller.
  30.         -- We'll do both
  31.         inputFontSize = 14
  32.         inputFontHeight = 42
  33.     end
  34.     defaultField = native.newTextField( 10, 80, 300, 30, fieldHandler )
  35.     defaultField.font = native.newFont( native.systemFontBold, inputFontSize )
  36.     defaultField.align = "center"
  37.     -- Add fields to our new group
  38.     fields:insert(defaultField)
  39.     local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
  40.     bkgd:setFillColor( 0, 0, 0, 0 )
  41.  
  42.     local listener = function( event )
  43.         -- Hide keyboard
  44.         print("tap pressed")
  45.         native.setKeyboardFocus( nil )
  46.         bkgd:removeEventListener("tap", listener)   ----------< This is line 196
  47.         bkgd:removeSelf()
  48.         verifyName(defaultField)
  49.     end
  50.  
  51.  
  52. ----------Error Produced----------------
  53.  
  54.  
  55. ERROR: nil key supplied for property lookup.
  56. stack traceback:
  57.     [C]: ?
  58.     [C]: ?
  59.     ?: in function 'removeEventListener'
  60.     /Users/eric/Documents/CRPG/scene_intro.lua:196: in function </Users/eric/Documents/CRPG/scene_intro.lua:192>
  61.     ?: in function <?:215>
  62. tap pressed
  63. Runtime error
  64.     ERROR: nil key supplied for property lookup.
  65. stack traceback:
  66.     [C]: ?
  67.     [C]: ?
  68.     ?: in function 'removeEventListener'
  69.     /Users/eric/Documents/CRPG/scene_intro.lua:196: in function </Users/eric/Documents/CRPG/scene_intro.lua:192>
  70.     ?: in function <?:215>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement