AS3:滑动功能失效



所以我做了一个滑动功能,允许用户从屏幕的顶部和屏幕的侧面滑动菜单(注意:有箭头是从屏幕的侧面,用户正在穿滑动菜单)。现在一切都很好,但有一件事…菜单只适用于事件侦听器中的.stage。这不会是一个问题,但我有一些屏幕也使用滑动功能来改变屏幕上的内容。但奇怪的是,使用滑动功能的屏幕不需要事件侦听器中的.stage。下面我将发布事件监听器,我已经在这上面呆了几天了,只是不明白为什么它会这样做。

//Side Menu Swipe
smenu_mc.stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);
//Top Menu Swipe
tmenu_mc.stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, downSwipe);
//Screens Swipe
Games.addEventListener(TransformGestureEvent.GESTURE_SWIPE, lrSwipe);

你能做的,是在一个显示对象(比如你的Games对象)的顶部发生的滑动,你可以用更高的优先级收听并取消事件。

Games.addEventListener(TransformGestureEvent.GESTURE_SWIPE, lrSwipe, false, 999); //the fourth parameter is the priority of the listener, when there are multiple event listeners for the same event, the listener with the higher number priority will be run first
function lrSwipe(e:TransformGestureEvent):void {
    e.stopImmediatePropagation(); //this make the event stop and not trigger other listeners after this one
    //...rest of your code
}

再次说明(正如我对您的另一个问题的回答所演示的那样),您不会希望为舞台滑动事件设置多个侦听器。使用您发布的代码,当用户在Games屏幕上方滑动时,您的所有三个函数(lrSwipe,然后downSwipe然后onSwipe)将同时被调用。

最新更新