[SOLVED] Touch listener not receving "ended" event

Hi,

First off - I do set the focus to the listener.

I have a table, where I keep reference to all active objects. I add them during “began” phase, modify during “move” phase and remove during “ended” and “cancelled” phases.

Like I’ve mentioned, first line of “began” handler has:

display:getCurrentStage():setFocus(self.touch, event.id)  

As usually, I can’t reproduce this error… it just happens from time to time.
The only thing I was able to get is that “ended” event is not send for one of the touches.

Anyone has any idea what could cause this?

Thanks [import]uid: 109453 topic_id: 26155 reply_id: 326155[/import]

Depends on the situation; I mean there are things like certain widgets that don’t use event.phase==“ended” and it’s possible you’re running into a situation where your touch event is hitting event.phase==“cancelled” instead? [import]uid: 41884 topic_id: 26155 reply_id: 105925[/import]

I am checking both: ended and cancelled :-\ [import]uid: 109453 topic_id: 26155 reply_id: 105931[/import]

What kind of objects?

Also, have you tried printing some detail on the object to make sure it’s not switching focus somehow at some point? (I usually give an object a name on .id and check for that…) [import]uid: 41884 topic_id: 26155 reply_id: 105936[/import]

They are actually references to events.
In began I insert them there and in ended/cancelled phase I loop through all of them, compare id’s and remove the one which ended. [import]uid: 109453 topic_id: 26155 reply_id: 105953[/import]

Finally we were able to spot how this is happening.

Although we are settings focus, when finger hovers over other items, which have touch listeners, they WILL be triggered! Once fired, when they have return true at the end, the touch listener which has the focus will not be triggered!
How am I supposed to deal with this?
Tested with both - stable release and current builds. [import]uid: 109453 topic_id: 26155 reply_id: 107249[/import]

I think it’s really hard to say without getting some code clips of your methodology. Here’s a sample code project that works as intended:

  1. Touch and hold the green square to maintain focus.
  2. So long as you do not release, the red square cannot print any statements.

[code]local object1 = display.newRect(0,0,32,32)
object1:setFillColor(0,255,0)
object1.x, object1.y = 200,200

local object2 = display.newRect(0,0,48,32)
object2:setFillColor(255,0,0)
object2.x, object2.y = 500,500

local function touch1(event)
if event.phase == “began” then
print(“grabbing focus”)
display:getCurrentStage():setFocus(event.target)
elseif event.phase == “moved” then

elseif event.phase == “ended” then
print(“releasing focus”)
display:getCurrentStage():setFocus(nil)
end
end

local function touch2(event)
if event.phase == “began” then
print(“WHA!?!?!?”)
elseif event.phase == “moved” then
print(“HUH?!!??!”)
elseif event.phase == “ended” then

end
return true
end

object1:addEventListener(“touch”, touch1)
object2:addEventListener(“touch”, touch2)[/code] [import]uid: 41884 topic_id: 26155 reply_id: 107361[/import]

Hi richard9,

thanks for spending few moments with this.
I’ve made mistake in my code, and instead of switching focus to an object, which has a touch listener, I was switching to object without one.

Thanks a lot! [import]uid: 109453 topic_id: 26155 reply_id: 107457[/import]