Cancelling Button Press

How do I cancel a button press event if the user drags finger off the button.

I have tried adding :

[lua]if e.phase == “cancelled” then
print (“Cancelled”)
end[/lua]
but I’m not sure how to implement this

the button still triggers the “began” or “ended” event even when the user has dragged finger off the button

Thnaks
[import]uid: 142733 topic_id: 27263 reply_id: 327263[/import]

[code]
e.phase == “moved” then

end
[/code] [import]uid: 13560 topic_id: 27263 reply_id: 110864[/import]

thanks,
but that recognises “moved” but still triggers the began or ended event event [import]uid: 142733 topic_id: 27263 reply_id: 110867[/import]

Hi there,
If this is a standard button, can you just use the “tap” listener variety instead of “touch”?

If you need to emulate a tap using a touch listener (and there are some instances you might, in fact I sometimes do), it might serve your purpose to try this:

On began phase:
theButton.inPress = true (inPress is a custom flag, not a Corona API call, name it whatever you wish)

On moved phase:
theButton.inPress = false

On ended phase:
if theButton.inPress == true then (perform your action) end
theButton.inPress = false

What this does is “cancel” the press if the user drags a sufficient distance as to trigger the “moved” phase. If you find that it’s too sensitive, there are more advanced ways to say how MUCH the user can move before the touch is cancelled, but try this and let me know if it works.

btw, the “cancelled” phase is only internal for the OS to force cancel a signal, i.e. perhaps if an incoming call comes to the phone, an active touch will be voided by the system.

Brent Sorrentino [import]uid: 9747 topic_id: 27263 reply_id: 110877[/import]

Thanks Brent,

That worked a treat I used the inPress method.

now my menu buttons are a lot slicker!

good info on the “cancelled” i did not know that
Many thanks [import]uid: 142733 topic_id: 27263 reply_id: 110898[/import]