Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
where is the variable drawn reset?
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
(there's no problem using scenes with as3.)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
check my edited message.
i changed it after adding that problematic code.
Copy link to clipboard
Copied
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 {
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now