Touch Event Phase Ended not firing

here is recoring on iOS Simulator and console output
http://www.youtube.com/watch?v=o2zjfJfCFTw&

If I drag across the table and release while on last cell I get the “touch ended” event phase. However if I drag across cells and release the mouse when I’m outside of cells only “touch started” phase will be reported while “touch ended” pahse will not be reported even though mouse has been released? This is happening both on Corona Simulator, iOS Simulator and on device.

How do I get touch ended phase if I go outside of table and the lift the finger? Application will not get the last event phase.

code to test this below:

main.lua

io.output():setvbuf("no")  
local cells = {}  
  
local selectedCells = {}  
  
local function unselectCells()  
 print "unselectCells()"  
 for i = 1, #selectedCells do  
 selectedCells[i].touched.isVisible = false  
 end  
end  
  
function handleEvent (event)  
 if event.phase == "began" then  
 print "touch began"  
 end  
 if event.phase == "moved" then  
 --print "touch moved"  
 end  
 if event.phase == "ended" then  
 print "touch ended"  
 timer.performWithDelay(500, unselectCells, 1)  
 end  
 tmpCell = event.target  
  
 tmpCell.touched.isVisible = true  
 if (tmpCell.spent == false) then  
 tmpCell.spent = true  
 table.insert(selectedCells, tmpCell)  
 end  
  
end  
  
function setupTable()  
 local startX = (display.contentWidth / 2) - 170  
 local startY = (display.contentHeight / 2) - 170  
  
 local tmpCell  
  
 for j=0,2 do  
 for i=0,2 do  
 cells[i] = display.newRect(0, 0, 160, 160)  
  
 tmpCell = cells[i]  
 tmpCell.spent = false  
 -- load buttons  
 tmpCell.touched = display.newRect(0, 0, 160, 160)  
 tmpCell.touched:setFillColor(140, 140, 140)  
  
 -- set button positions  
 tmpCell.x = startX + (i\*170)  
 tmpCell.y = startY + (j\*170)  
 tmpCell.touched.x = startX + (i\*170)  
 tmpCell.touched.y = startY + (j\*170)  
 tmpCell.touched.isVisible = false  
  
 -- add event listener to standard button  
 tmpCell:addEventListener("touch", handleEvent)  
 end  
 end  
end  
  
setupTable()  

cofing.lua

application = { content = { width = 640, height = 960, scale = "letterBox", fps = 30, } [import]uid: 13099 topic_id: 28413 reply_id: 328413[/import]

You need to set focus to the item you are touching and remove focus once it has ended otherwise it will not fire the ended phase once the finger touches another object that has a listener. Check this thread for more details
http://developer.coronalabs.com/forum/2012/05/10/touch-listener-not-receving-ended-event
I hope this helps! [import]uid: 126161 topic_id: 28413 reply_id: 114699[/import]

Tom’s advice under this thread might be of interest too:

https://developer.coronalabs.com/forum/2012/02/07/cancelling-touch-event#comment-86138

In my case, even when the finger is no longer touching an object, touch ended event wouldn’t trigger under a certain circumstance, and dispatching event (as suggested by Brent @IgnisDesign) was the only way to work around the situation I faced.

Naomi [import]uid: 67217 topic_id: 28413 reply_id: 114864[/import]