TouchUpOutside Help?

I’m a bit surprised I’ve not found anything on this topic, but how do I detect when a user untouches the screen after having pressed it. For example, an onscreen button.

From what I can tell so far, my problem stems from the “ended/canceled” condition is never triggered in my touch function if the user moves his/her finger outside of my button image.

Here’s the code I’ve been using:

local p1\_btn\_left;  
p1\_btn\_left = display.newCircle( 20, display.contentHeight-40, 20 );  
  
local function onButtonTouch(self,e)  
 --print ("phase: " .. e.phase)  
 if e.phase == "began" then  
 print ("BEGAN")  
 elseif e.phase == "moved" then  
 print ("MOVED")  
 if e.x \> self.contentBounds.xMax or   
 e.x \< self.contentBounds.xMin or   
 e.y \> self.contentBounds.yMax or   
 e.y \< self.contentBounds.yMin then  
 print ("OUT!!!")  
 end  
 elseif e.phase == "ended" or e.phase == "cancelled" then  
 print ("ENDED")  
 end  
end  
p1\_btn\_left.touch = onButtonTouch  
p1\_btn\_left:addEventListener( "touch", p1\_btn\_left )  

I can see in the console when I touch my object, the BEGAN gets written, when I move the MOVED gets written, but if I let go of the screen outside of the button I never get an ENDED. Actually, I also never get an OUT either… I was trying to see if I can detect when the touch event MOVED out of the button bounds, but that didn’t do anything…
Do I need a runtime event listener to detect this condition? [import]uid: 100618 topic_id: 29489 reply_id: 329489[/import]

In order to be sure to get the “ended” event whether it occurs within or outside the object, you have to set focus to the object on the “began”.

Do this on “began”

display.getCurrentStage():setFocus(event.target)

and do this on “ended”/“cancelled”

display.getCurrentStage():setFocus(nil)
[import]uid: 160496 topic_id: 29489 reply_id: 118384[/import]

Thanks Mike for the quick response! That was what I was looking for! [import]uid: 100618 topic_id: 29489 reply_id: 118385[/import]