Hi, everyone!
I faced the situation when i need to add Runtime listener to some object, and the listener function should be that object method.
I wrote simple example below:
[lua]r = display.newRect (100, 100, 100, 100)
r:setFillColor(255,255,255)
function r:test()
return function(event)
print ‘hit back!’
end
end
function reload(event)
print ‘re…’
Runtime:removeEventListener(‘tap’, test)
Runtime:addEventListener(‘tap’, r:test())
print ‘moved’
return true
end
function main()
r:addEventListener (‘tap’, reload)
Runtime:addEventListener(‘tap’, r:test())
end
main()[/lua]
I want the Runtime listener removed each time, i press white rect.But know, it creates new Runtime listeners and doesn’t delete old.How can I fix this?
Thanks! [import]uid: 41345 topic_id: 14001 reply_id: 314001[/import]