Search code examples
actionscript-3swipetouch-event

How to stop Touch or Click Event while Swipe Event is in action in as3


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;
        }
    }
 }

Solution

  • 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
        }
    }