[Resolved] About touch event cancelled

I have a problem when moving my character with a button, but it will apply to every button I have with a event phase cancelled or ended I’ll have, so I better ask this now. I don’t really know how the cancelled works, but it’s not working for me, if I touch the button and drag the mouse outside of the button and unclick while outside, for some reason the event didn’t get the event.ended or cancelled and so the character’s movement didn’t stop.

This is what I have:

function moveRight:touch(event)
moveX = speed;

if event.phase ==“ended” or event.phase==“cancelled” then
moveX = 0;
end
return true
end
moveRight:addEventListener(“touch”,moveRight)

local function moveCharacter (event)
character.x = character.x + moveX;
end
Runtime:addEventListener(“enterFrame”, moveCharacter )

The character keeps moving when I drag the mouse and unclick outside of the button, I want it to not count it as clicked anymore and have the moveX reset to 0. What can I do?

Also, is this the best way to manage the character movement?
[import]uid: 53195 topic_id: 33330 reply_id: 333330[/import]

Hello,
This is a common misunderstanding. The ended event only happens when the touch ends ON the object itself. If you move outside the object and release, you’ll get no ended response. One solution is to place another sensory object behind the buttons (or use the entire stage) and sense an ended phase on that… it will equate to the touch ending “off the button”.

Cancelled phase is only triggered by the system canceling the response. It doesn’t happen often… I think only perhaps if a call comes through or something. Still, you should usually test for it along with the ended phase, to be sure.

Hope this helps,
Brent [import]uid: 9747 topic_id: 33330 reply_id: 132353[/import]

Set the focus to the object when you touch it.

http://developer.coronalabs.com/reference/index/stagesetfocus

Then all events will be sent to your object, regardless of where on the screen they are.

You can use this to ensure the “ended” event is fired. [import]uid: 36578 topic_id: 33330 reply_id: 132368[/import]

Mateosolares, that helped a lot, thank you very much ^^ [import]uid: 53195 topic_id: 33330 reply_id: 132370[/import]

Hello,
This is a common misunderstanding. The ended event only happens when the touch ends ON the object itself. If you move outside the object and release, you’ll get no ended response. One solution is to place another sensory object behind the buttons (or use the entire stage) and sense an ended phase on that… it will equate to the touch ending “off the button”.

Cancelled phase is only triggered by the system canceling the response. It doesn’t happen often… I think only perhaps if a call comes through or something. Still, you should usually test for it along with the ended phase, to be sure.

Hope this helps,
Brent [import]uid: 9747 topic_id: 33330 reply_id: 132353[/import]

Set the focus to the object when you touch it.

http://developer.coronalabs.com/reference/index/stagesetfocus

Then all events will be sent to your object, regardless of where on the screen they are.

You can use this to ensure the “ended” event is fired. [import]uid: 36578 topic_id: 33330 reply_id: 132368[/import]

Mateosolares, that helped a lot, thank you very much ^^ [import]uid: 53195 topic_id: 33330 reply_id: 132370[/import]