hello im trying to make my gotoAndStop button as swipe instead of onpress. but it only work once, the second frame i make is not working anymore and i dont know the error please help me , thanks
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);
}
}
this code is working but when i try to make another code same as this in different frame its not working anymore, i also change the instance name so it wont dupplicate
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 i also try to change onSwipe2 to onSwipe , but error comes saying its duplicate
Well this is not the clean way of doing this by having two similar functions but that's another topic :) I assume the problem is that when you do the swipe the second time BOTH event listeners are getting the swipe event and both try to gotoAndPlay. Try to remove the event listener on swipe:
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);
}
}
A better approach would be to have just ONE event listener on the stage and have one function that would bring the player to the right chapter depending on where you currently are, then you would not need to mess around with several functions but have everything in one place