Skip to main content
Known Participant
September 4, 2012
Answered

Detect double tap of a button

  • September 4, 2012
  • 1 reply
  • 1702 views

I am creating an app for very young children and want to keep them out of the settings screen within my game.

I was planning to do this by requiring a double tap on the settings button but not sure how to detect a double tap

The app is for iPad only.

This topic has been closed for replies.
Correct answer Colin Holgate

Setting doubleclickenabled won't help in this case, because that only works for textfields under iOS. You can just use a MouseEvent.CLICK listener, and make a note of the getTimer(). If the new click is less than a certain amount of time since the last one, then it's a double tap. You could go further and make sure that a third tap doesn't happen too soon, otherwise the kids could just frantically tap on the button to get through.

Here's something useful that someone made to measure any given number of taps:

https://github.com/fljot/Gestouch

With that you could add a listener like this:

var doubleTap:TapGesture = new TapGesture(myButton);

doubleTap.numTapsRequired = 2;

doubleTap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onDoubleTap);

...

private function onDoubleTap(event:GestureEvent):void

{

// handle double tap!

1 reply

Colin Holgate
Colin HolgateCorrect answer
Inspiring
September 4, 2012

Setting doubleclickenabled won't help in this case, because that only works for textfields under iOS. You can just use a MouseEvent.CLICK listener, and make a note of the getTimer(). If the new click is less than a certain amount of time since the last one, then it's a double tap. You could go further and make sure that a third tap doesn't happen too soon, otherwise the kids could just frantically tap on the button to get through.

Here's something useful that someone made to measure any given number of taps:

https://github.com/fljot/Gestouch

With that you could add a listener like this:

var doubleTap:TapGesture = new TapGesture(myButton);

doubleTap.numTapsRequired = 2;

doubleTap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onDoubleTap);

...

private function onDoubleTap(event:GestureEvent):void

{

// handle double tap!

P StevenAuthor
Known Participant
September 4, 2012

Thank you Colin. I was thinking of using a timer if I did not find any built in solution though I had not thought of the possibility of the kid frantically clicking so checking for a third click is a great idea.

I will look at the Gestouch offering too. Looks like it may offer just what I am after.

Many thanks