lua - How can I remove onEvent from button widget in Corona? -
i trying remove onevent listener button widget. tried assign nil onevent attribute didn't work , lastly tried this:
buttonwidget : removeeventlistener("touch", buttonwidget.onevent)
i have several button , stopped button's event listeners. suggest? how can remove event listener 1 button widget? thanks.
here how create button widgets:
for i=0,2 j=0,8 count=count+1 letterbtn[count] = widget.newbutton{ id = alphabet[count], left = 5+j*50, top = h-160+i*50, label = alphabet[count], width = 45, height = 45, font = nil, fontsize = 18, labelcolor = { default = {0,0,0}, on = {255,255,255}}, onevent = btnoneventhandler }; end end
can tell me how can remove onevent later?
okey, tried button: setenabled(false) still disables buttons not one. tried second advice gives same result. copying rest of code. can please @ , tell me missing?
local function checkletter(e) if(guessword) i=1, #guessword local c = guessword:sub(i,i) if c==e.target.id letter[i].text = e.target.id lettercount = lettercount +1 print("lettercount"..lettercount) e.target:setenabled(false) end end if (lettercount == #guessword , not hanged) timer.performwithdelay(500, function() lettercount=0 rightwguess = rightwguess+1 k,v in pairs(notguessedword) if v == guessword notguessedword[k]=nil end end enablebuttons() startgame() end ,1) end end end local function btnoneventhandler(e) if(e.phase == "began") checkletter(e) print(e.target.id) end return true end
if want temporarily (or permanently) stop button responding touch events, can use button:setenabled(false).
the following worked me removing listener 2 buttons. button 1 , 3 stopped responding events expected while 2, 4, , 5 still did.
update: disable, have on 'ended' phase or corona gets confused.
widget = require 'widget' local function btnoneventhandler(event) print('event', event.target.id, event.phase) if event.phase == 'ended' -- disable button can't clicked again -- must disable in end state or corona gets -- confused event.target:setenabled(false) end end local buttons = {} i=1,5 buttons[i] = widget.newbutton{ id = 'button' .. i, left = display.contentcenterx - 50, top = 60 * i, label = 'button ' .. i, width = 100, height = 50, onevent = btnoneventhandler } end buttons[1]:removeeventlistener('touch', buttons[1].onevent) buttons[3]:removeeventlistener('touch', buttons[3].onevent)
Comments
Post a Comment