I have a runtime touch listener.
how can I cancel the “moved” event or tell the listener that the event is now “ended” ?
does return true only work in the “ended” phase?
any help appreciated.
I have a runtime touch listener.
how can I cancel the “moved” event or tell the listener that the event is now “ended” ?
does return true only work in the “ended” phase?
any help appreciated.
Hi @romanfischer,
Have you tried dispatching a “fake” ‘ended’ event to the listener using “object:dispatchEvent()”? This method isn’t commonly used, but it’s really useful in some instances.
http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html
Brent
@romanfischer,
Is your goal to stop accepting swipe events before you get an “ended” phase?
If so, you can simply call removeEventLister() in your “moved” processing code.
Alternately, you can set a local or global flag to ignoreTouches and not process touches in the “ended” part of your code if the flag is set. (Don’t forget to clear it though.)
If you are still stuck on this please elaborate on the sequence of events and what you want to happen.
One more note:
return true tells tells the event dispatch system, “Hey, this event has been serviced and does not need to be passed onto any other listeners that may be waiting to get it.”
It effectively stops the processing of that specific touch event.
That said, touch events are multi-phased. “began”, "moved’, “moved”, …, “ended”
Each of these phases results in a new event being dispatched. Returning true only stops the processing for the current phase of that touch.
One more note. If you have multiple ‘touch’ listeners attached to the same object, returning true will not stop the other listeners attached to that object from getting the event.
Event propagation is only stopped between objects when returning true.
Please see docs here for more: http://developer.coronalabs.com/content/application-programming-guide-event-handling
Hey Brent and Roaminggamer,
thank you very much for your detailed answers, I will check it out and be back in case that I’ll have more questions.
Best,
Roman
Hi @romanfischer,
Have you tried dispatching a “fake” ‘ended’ event to the listener using “object:dispatchEvent()”? This method isn’t commonly used, but it’s really useful in some instances.
http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html
Brent
@romanfischer,
Is your goal to stop accepting swipe events before you get an “ended” phase?
If so, you can simply call removeEventLister() in your “moved” processing code.
Alternately, you can set a local or global flag to ignoreTouches and not process touches in the “ended” part of your code if the flag is set. (Don’t forget to clear it though.)
If you are still stuck on this please elaborate on the sequence of events and what you want to happen.
One more note:
return true tells tells the event dispatch system, “Hey, this event has been serviced and does not need to be passed onto any other listeners that may be waiting to get it.”
It effectively stops the processing of that specific touch event.
That said, touch events are multi-phased. “began”, "moved’, “moved”, …, “ended”
Each of these phases results in a new event being dispatched. Returning true only stops the processing for the current phase of that touch.
One more note. If you have multiple ‘touch’ listeners attached to the same object, returning true will not stop the other listeners attached to that object from getting the event.
Event propagation is only stopped between objects when returning true.
Please see docs here for more: http://developer.coronalabs.com/content/application-programming-guide-event-handling
Hey Brent and Roaminggamer,
thank you very much for your detailed answers, I will check it out and be back in case that I’ll have more questions.
Best,
Roman