0

In my code i use both swipe gesture and click event at the same time. How to avoid click event or touch event while swipe gesture is in action?

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);
wall.tile[0].addEventListener(MouseEvent.CLICK, showBook());
wall.tile[1].addEventListener(MouseEvent.CLICK, showBook());

 public function fl_SwipeHandler(event:TransformGestureEvent):void
   {
     switch(event.offsetY)
     {
        // swiped down
        case 1:
        {
        if (swipe!=0){
             Tweener.addTween(wall, {y: wall.y + 650, time:.5, transition:"easeOutSine" } );
             swipe--;
             }
        // End your custom code
        break;
        }
        // swiped up
        case -1:
        {
        if (swipe<=(total/5)){
             Tweener.addTween(wall, { y: wall.y - 650, time:.5, transition:"easeOutSine" } );
             swipe++;
             }
        // End your custom code
        break;
        }
    }
 }
Sankar R
  • 25
  • 4
  • I even used Stoppropogation() and useCapture, priority stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler, true, 1); tile.addEventListener(MouseEvent.CLICK, showBook, false, -1); public function showBook(MouseEvent):void { e.stopImmediatePropagation(); } – Sankar R Oct 14 '15 at 09:18

1 Answers1

0

I usually have some boolean variable set to true when swipe is being activated, and onComplete function of tweener sets it back to false. And that boolean is one condition in my onClick functions (as false obviously):

public var swipeOn:Boolean;

public function fl_SwipeHandler(event:TransformGestureEvent):void{
     switch(event.offsetY){
        case 1:{
            if (swipe!=0){
                swipeOn = true;
                Tweener.addTween(wall, {y: wall.y + 650, time:.5, transition:"easeOutSine", onComplete:doneSwipe } );
                swipe--;
            }
            break;
        }

        case -1:{
            if(swipe<=(total/5)){
                swipeOn = true;
                Tweener.addTween(wall, { y: wall.y - 650, time:.5, transition:"easeOutSine", onComplete:doneSwipe } );
                swipe++;
            }
            break;
        }
    }
}

public function doneSwipe():void{
    swipeOn = false;
}

public function showBook(Event:MouseEvent):void{
    if(!swipeOn){
        //....handle your clicks etc
    }
}
kaarto
  • 747
  • 1
  • 8
  • 18
  • Thanks for the answer dude. But i added one code inside the **function fl_SwipeHandler()** that is, 'swipeOn = true;' – Sankar R Oct 16 '15 at 10:40
  • Can you answer me one more question? Actually **showbook()** opens a starling, when we come to the main screen after **starling.dispose()** TransformGestureEvent is not working. I even used **stage.removeEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);** inside **showbook()** – Sankar R Oct 16 '15 at 10:47