Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why does my gesture_swipe not work twice?

New Here ,
May 02, 2013 May 02, 2013

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

TOPICS
ActionScript
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2013 May 02, 2013

where is the variable drawn reset?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 02, 2013 May 02, 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 02, 2013 May 02, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 02, 2013 May 02, 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2013 May 02, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2013 May 02, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2013 May 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2013 May 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2013 May 03, 2013

I do indeed have multiple gesture_swipes on different layers... I have no idea what one of these is, but i'll have a read into it - thank you kglad

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2013 May 03, 2013

try:

MovieClip(root).ed = new EventDispatcher();

MovieClip(root).ed.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 {

         MovieClip(root).ed.removeEventListener(TransformGestureEvent.GESTURE_SWIPE,onStageSwipeDRAW);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2013 May 03, 2013

1119: Access of possibly undefined property EventDispatcher through a reference with static type flash.display:Stage.

I get that error

Do I need to declare a variable for it somewhere?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2013 May 03, 2013

check my edited message.

i changed it after adding that problematic code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2013 May 03, 2013

Unfortunately, still no luck after adding in that code.

The layout of my game is as follows.

Menu > Difficulty selection > Game

There are three frames for each different difficulty, each with their own:

stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAW);

function onStageSwipeDRAW (e:TransformGestureEvent):void {

I have just changed this by adding "a" and "b" to the end of each function to prevent duplication errors.

For example:

Level one is:

stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAW);

function onStageSwipeDRAW (e:TransformGestureEvent):void { ....

Level two is:

stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAWa);

function onStageSwipeDRAWa (e:TransformGestureEvent):void {

Level three is:

stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onStageSwipeDRAWb);

function onStageSwipeDRAWb (e:TransformGestureEvent):void {

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2013 May 03, 2013
LATEST

does the code i suggested work the first time you play and fail the 2nd time?

if yes and yes, confirm the same code is executing by use the trace statements i showed before, copying and pasting the code and copying and pasting the trace output.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines