Skip to main content
Known Participant
January 30, 2014
Question

Tap or Scroll? Understand the difference in AS3

  • January 30, 2014
  • 1 reply
  • 584 views

Hello everyone, I'm developing apps for iOS with Adobe AIR since years but...I always had this big problem: how to make the app understand if I'm tapping something or if I'm just scrolling it?

In my last product I basically have a scrolling menu with some options to activate. So I need a way to determinate if I'm tapping a MovieClip or just scrolling it. Can you help me?

Thank you so much guys, have a nice day!

This topic has been closed for replies.

1 reply

Known Participant
January 30, 2014

I use mouse down and mouse up events with a timer....when mousedown fires....timer starts....a tap would occur if the timer records less then 0.1 seconds....scroll would be longer....timer ends when the mouse up event fires....

?...instead of timer, you could also use a measure of distance from where the original touch took place to when the touch no longer is recorded.....less then a certain distance would represent a tap.....I have used a combo of both tecniques.....I stay away from touch events as they are more intensive on cpu.

Inspiring
February 1, 2014

I would not agree on using Timer event, instead I would use (and I've been using) this:

sprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

var moving:Boolean;

function mouseDownHandler(e:MouseEvent):void

{

  sprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

  sprite.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

  //record mouseX and mouseY in variable

}

function mouseMoveHandler(e:MouseEvent):void

{

  moving = true;

  //set sprite's coordinates

}

function mouseUpHandler(e:MouseEvent):void

{

  if (moving)

  {

   //it means it is scrolling

  } else

  {

    //it means it is a click only..
  }

}