Is there something similar to “if event.phase == “canceled””, but for when you move you finger of a button, so that it cancels the function. I have tried using event.phase == “moved”, but if my move my finger within the button it still cancels the functions. Basically is there anything for if your finger is outside the boundaries of the button? [import]uid: 116264 topic_id: 24894 reply_id: 324894[/import]
http://developer.anscamobile.com/reference/index/eventphase-0
“began” indicates a finger touched the screen.
“moved” indicates a finger moved on the screen.
“ended” indicates a finger was lifted from the screen.
“cancelled” indicates the system cancelled tracking of the touch.
so cancelled would work where you hold your finger down on the button and - slide it off of the button - and then lift your finger up - i am assuming, is that what your talking about? [import]uid: 11860 topic_id: 24894 reply_id: 101042[/import]
event.phase == “canceled” does not work. If I slide my finger off the button and then let go, it still performs the function of the button. Any other suggestions? [import]uid: 116264 topic_id: 24894 reply_id: 101056[/import]
send me a small sample if you like to support [a t] DoubleSlashDesign . com i’ll run it thru the CIDER debugger and tell you what i find.
Larry [import]uid: 11860 topic_id: 24894 reply_id: 101058[/import]
I have a small sample, so I will just post it here if that’s ok:
[code]local number = 0
print(number)
local button = display.newRect(50,50,50,50)
local function IncreaseNumber(event)
if event.phase == “began” then
function i ()
number = number+1
print(number)
end
t = timer.performWithDelay(10, i, 0)
elseif event.phase == “ended” or event.phase == “canceled” then
timer.cancel(t)
end
end
button:addEventListener(“touch”, IncreaseNumber)[/code]
If you click and hold the button, the number increase, and when you let go it stops. But if you click, hold and then drag your finger away the number keeps increasing. [import]uid: 116264 topic_id: 24894 reply_id: 101067[/import]
I’ve managed to solve the problem! I have added a screen sized button behind the number increasing button, and created a function to cancel the timer:
[code]local screen = display.newRect(0,0,_W,_H)
screen.alpha = 0.01
local function cancelTimer()
if t then
timer.cancel(t)
end
end
screen:addEventListener(“touch”, cancelTimer)[/code]
Thanks for your help! [import]uid: 116264 topic_id: 24894 reply_id: 101088[/import]
Sorry ( family came buy and took up my time )
Good Idea, I just tested this in the simulator and was surprised how it was working.
Really I think you should submit that as a bug. They need to fix that.
I can see that being an issue as I have used that exact thing in other peoples apps, and they worked how we both just expected here.
Larry [import]uid: 11860 topic_id: 24894 reply_id: 101150[/import]
+1 For that…
I tried using “focus” to detect a ended away from the button (since cancelled do not work), but this breaks my entire code too 
I REALLY need a way to detect that you moved your finger from a button, without doing fugly hacks of entire screen touch [import]uid: 142895 topic_id: 24894 reply_id: 116830[/import]
Cancelled has two L’s, at least in the country where the word was invented…
…have you tried it with the correct spelling?
[import]uid: 93133 topic_id: 24894 reply_id: 116833[/import]
The focus is how you’re supposed to do it.
Once you get a “began” event, you’re not guaranteed to get the “ended” event unless the user lifts his finger off the screen while *on* the object. If he lifts his finger while on top of some other object, that object gets the “ended” event and not yours.
To prevent that from happening, you add this line in the “began” part:
display.getCurrentStage():setFocus(event.target)
and you add this line in the “ended” part:
display.getCurrentStage():setFocus(nil)
[import]uid: 160496 topic_id: 24894 reply_id: 116900[/import]
mike470 and how you figured he lifted the finger OUTSIDE the object?
because “ended” when focus is active behaves like if the entire screen was the object [import]uid: 142895 topic_id: 24894 reply_id: 117775[/import]