Remove/add listener bug or feature...

I do not know it is a bug or feature but following code causes infinite loop, do you have any workaround for this issue?

[lua]local test = display.newImage(“box.PNG”)

local tapCount = 0
function tapped(event)
tapCount = tapCount + 1
print(“Tapped " … tapCount … " times.”)
event.target:removeEventListener(“tap”, tapped)
event.target:addEventListener(“tap”, tapped)
end

function createScreen()
test:addEventListener(“tap”, tapped)
end

function main()
createScreen()
end

main()[/lua]

[import]uid: 208004 topic_id: 34414 reply_id: 334414[/import]

Any idea related this topic? [import]uid: 204424 topic_id: 34414 reply_id: 136767[/import]

I have found the solution from documentation:

You cannot add an object event listener within the listener event for that object. You should add the listener event outside of the current listener using the timer.performWithDelay() API. Failing to do so will cause the new listener to be called immediately after the current listener returns.

[import]uid: 208004 topic_id: 34414 reply_id: 136771[/import]

Any idea related this topic? [import]uid: 204424 topic_id: 34414 reply_id: 136767[/import]

I have found the solution from documentation:

You cannot add an object event listener within the listener event for that object. You should add the listener event outside of the current listener using the timer.performWithDelay() API. Failing to do so will cause the new listener to be called immediately after the current listener returns.

[import]uid: 208004 topic_id: 34414 reply_id: 136771[/import]