Fast dragging and flicking

I have followed a tutorial on dragging a DisplayObject around the screen where the x,y are recorded at the start of the drag and once “ended” or “cancelled” the object was returned to the start.

It resulted in quick drags or flicks letting the object stay somewhere else. I adapted it so it recorded the original position upon creation but it still seems to be possible to flick an object to another position without “ended” or “cancelled” being fired.

Is there a solution? [import]uid: 163144 topic_id: 28893 reply_id: 328893[/import]

Hi there,

I haven’t encountered any situation where the “ended” or “cancelled” phases of a touch event are not fired appropriately. Therefore, I suspect something else is going wrong with your code. Would you be able to post a snippet?

  • Andrew [import]uid: 109711 topic_id: 28893 reply_id: 116379[/import]

You will not get “ended” event if the user raises the tip of the finger off the screen on an object that is different than the one where the touch “began”. In order to prevent that from happening, you have to

setFocus(event.target)

on the “began” phase, and

setFocus(nil)

on the “ended” phase. The “canceled” phase is very rare, I think, and does not happen in normal circumstances, but you can probably treat it same as “ended”. [import]uid: 160496 topic_id: 28893 reply_id: 116383[/import]

Yep great thanks that worked!

I added:

display:getCurrentStage():setFocus(event.target)

to my begin and that stops it dropping the object in mid air when you move the mouse/finger very fast. [import]uid: 163144 topic_id: 28893 reply_id: 116569[/import]