cancel touch event

I’ve something like this in my code.

[lua]function onTouch(event)
if (event.phase == “began”) then
flag = true;
elseif (event.phase == “ended”) then
flag = false;
end
end

btnTouch:addEventListener(“touch”,onTouch);[/lua]

But if my touch go out the boundary of that btnTouch my event never reach to “ended” phase and thus my flag remains true.

How can I cancel/end my touch event if touch goes out of the border of this button?

Thanks [import]uid: 7995 topic_id: 13593 reply_id: 313593[/import]

try this
[lua]function onTouch(event)
if (event.phase == “began”) then
print(“true”)
display.getCurrentStage():setFocus(event.target)
flag = true;
elseif (event.phase == “ended”) or event.phase == “cancelled” then
flag = false;
print(“false”)
display.getCurrentStage():setFocus(nil)
end
end

btnTouch:addEventListener(“touch”,onTouch);[/lua]
if you can see the samples provided by ansca you can see lots of tricks for this type of situation [import]uid: 12482 topic_id: 13593 reply_id: 49880[/import]

OK. Thanks.
I got it working by adding Runtime touch event and checking touch id and position with button position. [import]uid: 7995 topic_id: 13593 reply_id: 49881[/import]

okey :slight_smile: [import]uid: 12482 topic_id: 13593 reply_id: 49890[/import]