Adding other eventListeners during an event

Hi,

I have an eventlistener EL1 and an event listener EL2.
Now, I start registering EL1 to a runtime event.
When it triggers, I’d like to remove EL1, and add EL2 for the next time this event triggers.
However, when adding the eventListener EL2, it automatically triggers.

I assume this is because I directly alter the listener table, and corona iterates the table.
What would be a good solution to support my behaviour?

I’d prefer not returning true to stop the events from bubbling, because I have other eventlisteners listening to the event too.
[import]uid: 5942 topic_id: 15598 reply_id: 315598[/import]

@jbverschoor,
When you want to re-register a new trigger, is it a different handler that you want to register or is it a new event type?

Handlers are

obj:addEventListener("touch",Handler1)  
obj:addEventListener("touch",Handler2)  

Event Types are

obj:addEventListener("touch",Handler1)  
obj:addEventListener("tap",Handler1)  

because you can still make do with the same handler, in your handler, you can switch between using a flag to which function should handle the event using an if.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15598 reply_id: 57612[/import]

It’s the same event, but a different listener
[lua] local function listener2(event)
print(“listener2”)
Runtime:removeEventListener(“myevent”, listener2)
end

local function listener1(event)
Runtime:removeEventListener(“myevent”, listener1)
print(“EVENT1”)
Runtime:addEventListener(“myevent”, listener2)
end

Runtime:addEventListener(“myevent”, listener1)

– dispatch event[/lua]

I found that this works:
[lua] timer.performWithDelay(0, function()
Runtime:addEventListener(“myevent”, listener2)
end)[/lua]
[import]uid: 5942 topic_id: 15598 reply_id: 57615[/import]

You have a way to get things done, I have written a tutorial on a better modular scalable approach, if you or any other developer would want to read, it is here

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15598 reply_id: 57626[/import]