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

AIR swipe function doesn't work

Explorer ,
Jan 21, 2013 Jan 21, 2013

I'm using Swipe function from codesnippet, but this code doesn't work for some reason, it doesn't report an error, but doesn't work. I've placed code on Background MC as suggested.

Multitouch.inputMode = MultitouchInputMode.GESTURE;

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler_2);

function fl_SwipeHandler_2(event:TransformGestureEvent):void

{

    switch(event.offsetX)

    {

        // swiped right

        case 1:

        {

            MyMC.gotoAndStop(105);

            break;

        }

        // swiped left

        case -1:

        {

           

            MyMC.gotoAndStop(100);

            break;

        }

    }

}

TOPICS
ActionScript
5.8K
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
Guru ,
Jan 21, 2013 Jan 21, 2013

Put this line in fornt of your switch

trace(event.offsetX);

What do you get?

Another point:

Every switch condition needs a closing default statement.

case 1:

case 2:

default: break;

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 ,
Jan 21, 2013 Jan 21, 2013

That doesn't work what you said, produced more errors.

I used default codesnippet which should work, but it doesn't. Also please send full code so there are no mistakes, thanks.

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
Guru ,
Jan 21, 2013 Jan 21, 2013

Multitouch.inputMode = MultitouchInputMode.GESTURE;

stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler_2);

function fl_SwipeHandler_2(event:TransformGestureEvent):void

{

    trace(event.offsetX);

    switch (event.offsetX)

    {

            // swiped right

        case 1 :

            MyMC.gotoAndStop(105);

            break;

            // swiped left

        case -1 :

            MyMC.gotoAndStop(100);

            break;

        default :

            break;

    }

}

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 ,
Jan 21, 2013 Jan 21, 2013

Sorry but still produces error... not sure is the problem with 'break' or something else...

Can you check default code snippet, i don't understand why that won't work...

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013

Switch statements do not require a default. They're fall-through statements that will do nothing if no case is matched.

Before getting into devices and support, you applied the handler to the Stage. Any objects above the stage may interfere with that handler firing off in certain situations. Try applying the listener to the object you want to swipe (like a picture, container of pictures, etc).

Is this AIR project for a device? I've built many kiosks and have used gestures but on touchscreen desktops, laptops and gesture supporting trackpads and mice I've found swipe is not a gesture that is natively supported.

To get a list of supported gestures, open a new AS3 doc set to publish for AIR and run this:

import flash.ui.Multitouch;

import flash.ui.MultitouchInputMode;

Multitouch.inputMode = MultitouchInputMode.GESTURE;

for each (var item:String in Multitouch.supportedGestures)

{

   if (item == TransformGestureEvent.GESTURE_PAN)

       trace("Gesture Pan Supported");

   else if (item == TransformGestureEvent.GESTURE_ROTATE)

       trace("Gesture Rotate Supported");

   else if (item == TransformGestureEvent.GESTURE_SWIPE)

       trace("Gesture Swipe Supported");

   else if (item == TransformGestureEvent.GESTURE_ZOOM)

       trace("Gesture Zoom Supported");

}

Here's my trace on a laptop with both a multipoint touch trackpad and a touchscreen:

[SWF] Untitled-1.swf - 2496 bytes after decompression

Gesture Zoom Supported

Gesture Pan Supported

Gesture Rotate Supported

[UnloadSWF] Untitled-1.swf

Debug session terminated.

Notice (annoyingly) no swipe is supported.

Bottom line is detecting and handling a swipe is very easy. Once an object is clicked, add a listener to the stage, listen for movement and if you receive it, do something based on it. Enable drag, consider it a swipe (based on the direction moved), etc. I think the swipe is so poorly supported by devices because it's so simple to implement.

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 ,
Jan 21, 2013 Jan 21, 2013

@sinious - if swipe is that simple why it won't work , I just need to swipe left and right, which should use gotoAndStop function, don't need anything else. But I don't understand why it won't work.

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013

The main question is are you exporting for a device (tablet/phone) or a desktop application? Desktop applications have basic touchscreens and touchinputs that are notorious for not supporting Swipe gestures.

If it's desktop, open a new AS3 doc, paste my full code example above, select AIR, run it and see what trace() reports for supported gestures. If there is no Swipe, you know why it's not working. That reason why is my last paragraph. Swipe is very easy to do using traditional Flash programming. And the hardware is more on the fault side than Flash.

If it's a device like a tablet/phone, it should definitely support swipe. All Android tablets/phones and all iPhone/iPads/iPods support swipe.

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 ,
Jan 21, 2013 Jan 21, 2013

I'm using swipe on Samsung Galaxy S3 smartphone (Android 4.x). But this code doesn't work, even though I need very simple function gotoAndStop, still can't make it to work.

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013

I have an SGS3 running JellyBean myself, I'll make a quick full source example in Flash Pro CS5.5 (lowest version that exports AIR for Android reliably) for you to test and post back.

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013

SGS3 works perfectly fine with swipe.

Here's a CS5.5 FLA (openable in CS5.5/CS6/CS7 Beta) set for AIR for Android (I use 3.5.0.1060). I am not exporting for captive runtime (cannot do it via CS5.5, only Flash Builder or CS6). Have AIR installed and up to date on your SGS3.

Source Files (includes a junk 'temp.p12' with a password of 'temp').

Includes a premade APK. If you need a link to the premade APK online PM me. Otherwise I'd suggest just connecting via USB, loading the FLA and running it.

If you just want to see the simple source:

http://pastebin.com/Wm28kpuu

Here's an example screenshot:

Screenshot_2013-01-21-10-27-03.png

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 ,
Jan 21, 2013 Jan 21, 2013

Ok so how do I use swipe for only moving screen left or right with gotoandstop function?

I used this code from default code snippets but didn't work:

Multitouch.inputMode = MultitouchInputMode.GESTURE;

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler_2);

function fl_SwipeHandler_2(event:TransformGestureEvent):void

{

    switch(event.offsetX)

    {

        // swiped right

        case 1:

        {

            MyMC.gotoAndStop(105);

            break;

        }

        // swiped left

        case -1:

        {

            MyMC.gotoAndStop(100);

            break;

        }

    }

}

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013

If you have a MovieClip on your timeline where that code is executed named "MyMC" then it will work.

To verify it exists, try updating the function to this:

function fl_SwipeHandler_2(event:TransformGestureEvent):void

{

    switch(event.offsetX)

    {

        // swiped right

        case 1:

        {

            trace("MyMC: " + MyMC + " Swiping Right");

            MyMC.gotoAndStop(105);

            break;

        }

        // swiped left

        case -1:

        {

            trace("MyMC: " + MyMC + " Swiping Left");

            MyMC.gotoAndStop(100);

            break;

        }

    }

}

Export over USB for debugging so you can see the trace() statements. See if they trace properly.

Did the example provided above work for 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
Explorer ,
Jan 21, 2013 Jan 21, 2013

For debugging, if you mean ADB I'm not at that level yet 🙂

Unfortunately this also didn't work, I tried it on background as MovieClip and tried one smaller object as MC also, it won't go anywhere

I don't wanna bug you too much, thanks anyway.

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013

We are here to help.

The .zip file I linked above with source files has an .apk you can install directly on your SGS3. If you install it, swipe your finger on the red box. Do you see the text updating saying you are swiping left and right? Then you have the code in the FLA necessary to perform a proper swipe.

If it all works for you and fixes your issue please mark helpful/correct responses. Good luck!

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 ,
Jan 21, 2013 Jan 21, 2013

Yes your sample works, but I don't know how to make gotoandstop function to work with same swiping.

Can you try it and test it with that function and see if it works, if yes please send that code that works. Thanks a bunch!

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013
LATEST

If the swipe code works then you're not accessing the MovieClip. That's why I mentioned to trace it, like I said above:

case 1:

   trace("MyMC: " + MyMC + " Swiping Right");

   MyMC.gotoAndStop(105);

   break;

case -1:

   trace("MyMC: " + MyMC + " Swiping Left");

   MyMC.gotoAndStop(100);

   break;

Note the lines in bold. See what the output window shows you. If you see "null" or "undefined" then you know "MyMC" does not exist and/or the code cannot see it. Let me know if that happens.

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