如何在as3中执行滑动事件时停止触摸或单击事件

时间:2015-10-14 07:48:58

标签: actionscript-3 swipe touch-event

在我的代码中,我同时使用滑动手势和点击事件。如何在滑动手势操作时避免点击事件或触摸事件?

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

1 个答案:

答案 0 :(得分:0)

当激活滑动时,我通常将一些布尔变量设置为true,并且tweener的onComplete函数将其设置为false。那个布尔值是我的onClick函数中的一个条件(显然是假的):

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