滑动手势,As3

Swipe Gesture, As3

你好,我正在尝试将我的 gotoAndStop 按钮设置为滑动而不是按下。但它只工作一次,我制作的第二帧不再工作,我不知道错误请帮助我,谢谢

 Multitouch.inputMode = MultitouchInputMode.GESTURE;


story1chapter3.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
function onSwipe (e:TransformGestureEvent):void{
if (e.offsetX == 1) { 
//User swiped towards right(back button)
story1chapter3.x += 100;
gotoAndStop(31);
}
if (e.offsetX == -1) { 
//User swiped towards left(next)
story1chapter3.x -= 100;
gotoAndStop(159);
} 
}

这段代码可以工作,但是当我尝试在不同的框架中制作另一个与此相同的代码时,它不再工作了,我还更改了实例名称,因此它不会重复

Multitouch.inputMode = MultitouchInputMode.GESTURE;


 story1chapter2.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
 function onSwipe2 (e:TransformGestureEvent):void{
 if (e.offsetX == 1) { 
  //User swiped towards right(back button)
 story1chapter2.x += 100;
 gotoAndStop(30);
 }
 if (e.offsetX == -1) { 
  //User swiped towards left(next)
  story1chapter1.x -= 100;
   gotoAndStop(27);
    } 
    }

PS 我也尝试将 onSwipe2 更改为 onSwipe ,但错误提示它重复

好吧,这不是通过具有两个相似功能来执行此操作的干净方法,但这是另一个主题 :) 我认为问题是当您第二次进行滑动时,两个事件侦听器都获得了滑动事件并且两者尝试转到 AndPlay。尝试删除滑动事件监听器:

story1chapter3.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
function onSwipe (e:TransformGestureEvent):void{
  if (e.offsetX == 1) { 
  //User swiped towards right(back button)
  story1chapter3.x += 100;
  story1chapter3.removeEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
  gotoAndStop(31);
}
  if (e.offsetX == -1) { 
  //User swiped towards left(next)
  story1chapter3.x -= 100;
  story1chapter3.removeEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
  gotoAndStop(159);
} 
}

更好的方法是在舞台上只有一个事件侦听器,并有一个功能可以根据您当前所在的位置将玩家带到正确的章节,这样您就不需要搞乱多个功能但一切都集中在一处