Skip to main content
Participating Frequently
May 2, 2013
Question

Why does my gesture_swipe not work twice?

  • May 2, 2013
  • 3 replies
  • 2340 views

I have a game in which the user has to draw his pistol and then shoot targets. The user draws their pistol with an upward swipe on the screen (and can only do so once). The drawn boolean is to stop the user swiping twice. I have also removed the gesture swipe from the stage after it has been used once as an extra precaution.

stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAW);

function onStageSwipeDRAW (e:TransformGestureEvent):void {

                if (drawn == false) {

                                if (e.offsetY == -1) {

                                                pistol_mc.gotoAndPlay("drawGun");

                                                drawn = true;

                                                removeSwipeListeners();

                                }

                }

}

//remove Listeners

function removeSwipeListeners ():void {

          stage.removeEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAW);

}

Basically, my issue is, that when I send the player back around to the start of the game, they can no longer draw. No error, nothing, the function is just unresponsive.

If anyone has any ideas why this may be, that would be great, thank you.

(or any questions)

Thank you

This topic has been closed for replies.

3 replies

kglad
Community Expert
Community Expert
May 2, 2013

what do the following traces show when replaying:

trace("added",drawn)

stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAW);

function onStageSwipeDRAW (e:TransformGestureEvent):void {

trace("function");

                if (drawn == false) {

                                if (e.offsetY == -1) {

                                                pistol_mc.gotoAndPlay("drawGun");

                                                drawn = true;

                                                removeSwipeListeners();

                                }

                }

}

//remove Listeners

function removeSwipeListeners ():void {

          stage.removeEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAW);

}

Basically, my issue is, that when I send the player back around to the start of the game, they can no longer draw. No error, nothing, the function is just unresponsive.

If anyone has any ideas why this may be, that would be great, thank you.

(or any questions)

Thank you

Banno92Author
Participating Frequently
May 3, 2013

This is my output when playing through the game.

OUTPUT:

added false          <---entering game frame

function               <---drawing pistol

added false          <---re-entering game frame

it still won't let me swipe upward to enter the function though

kglad
Community Expert
Community Expert
May 3, 2013

at any time, do you add a TransformGestureEvent.GESTURE_SWIPE to another object?

if yes, you need to add an event dispatcher to the stage.

Participating Frequently
May 2, 2013

May be in your case problem is with gotoAndStop('MAINMENU', "Scene 1");

don't use scene, in as3 using scenes are not recomended.

just use gotoAndStop('MAINMENU');

is this helpfull..?

Thanks,

Bala

Banno92Author
Participating Frequently
May 2, 2013

Thanks for replying to this bala. I originally had everything within one scene but it still didn't work. I only made it have two scenes in the hope that it may reset the offetY gesture...

But thank you, i was unaware using different scenes isn't good!

kglad
Community Expert
Community Expert
May 2, 2013

(there's no problem using scenes with as3.)

kglad
Community Expert
Community Expert
May 2, 2013

where is the variable drawn reset?

Banno92Author
Participating Frequently
May 2, 2013

It is reset on a button press in a later frame that sends you back to the main menu.

backtomenuEND_btn.addEventListener(MouseEvent.MOUSE_DOWN, gotoMAINMENUEND);

function gotoMAINMENUEND (e:MouseEvent):void {

          drawn = false;

          gotoAndStop('MAINMENU', "Scene 1");

          stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAW);

}

I also try to add the gesture swipe function back here too.

(ps thank you for replying)