Move-Out / Move-In Touch Event

I have a button that sets a variable to n when touched and back to 0 when un-touched. I have the basic code working but the problem is that when the button is touched, then the finger is moved out of the button, no ended event is triggered, so the variable is never set back to 0, which messes up my game. I’m asking if there is anyway to detect if a touch event moves out of the target’s bounding box.

Also, I realize that I can setup a global touch listener and check if the point of the touch event hits the button, but there a lot of buttons and it would get laggy and really hard to code.

Thanks a ton! [import]uid: 7202 topic_id: 7618 reply_id: 307618[/import]

This might be what you are looking for;

display.getCurrentStage():setFocus( self )

–Here is how it is used.
function button:touch( event )
local phase = event.phase
if “began” == phase then
– Subsequent touch events will target button even if they are
– outside the stageBounds of button
display.getCurrentStage():setFocus( self )
else

end

return true
end [import]uid: 18679 topic_id: 7618 reply_id: 27121[/import]

It didn’t work. Still behaves the same. Here is my code:

[code]
function tapButton(event)
if(event.phase == “began”) then
n = 100
display.getCurrentStage():setFocus(self)
end
if(event.phase == “ended”) then n = 0 end
end

button:addEventListener(“touch”, tapButton)
[/code] [import]uid: 7202 topic_id: 7618 reply_id: 27152[/import]