Skip navigation
Currently Being Moderated

SimController - Touch and gesture not working

Nov 26, 2012 4:49 AM

I'm running the "demo_mobile" Starling 1.2 sample in the trial version of flash CS6 on Windows 7.

When I crtl-enter to run it in the IDE, or go via Debug > Debug Movie > in Air Debug Launcher, I see the SimController appear.

I navigate to the Touch and gesture panel and tick the box to activate the semi-transparent touch layer over my running swf.

I see the little 'glow' icon to show where my touch should occur, but my clicks/touches are never registered.

I've tried this with Air 3.2, Air3.4, Air 3.4.0.2540 and Air 3.5.0.690 with the same negative results.

 

Am I missing something simple here?

 

cheers,

Alex

 
Replies
  • Currently Being Moderated
    Nov 26, 2012 7:45 AM   in reply to alex.harrison

    How are you checking to see if they're registered? You're seeing a glow so something is receiving and responding to them.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 26, 2012 9:02 AM   in reply to alex.harrison

    Are you saying you desire TouchEvent to work on desktop or you simply tried it as a desktop app to see if it would work?

     

    TouchEvent works for me perfectly fine in both AIR for Mobile and AIR for Desktop. Here's simple sample code for a AS for Mobile project:

     

    Main.as:

     

    package

    {

        import flash.display.Sprite;

        import flash.events.Event;

        import flash.geom.Rectangle;

       

        import starling.core.Starling;

       

        [SWF(frameRate=60,width=768,height=1024)]

        public class Main extends Sprite

        {

            private var _starling:Starling;

           

            public function Main()

            {

                addEventListener(Event.ACTIVATE, _onActivate);

                Starling.multitouchEnabled = true;

            }

           

            protected function _onActivate(event:Event):void

            {

                removeEventListener(Event.ACTIVATE, _onActivate);

               

                // start starling, iPad portrait

                _starling = new Starling(TouchDemo, this.stage, new Rectangle(0,0,768,1024));

                _starling.start();

            }

           

        }

    }

     

    TouchDemo.as:

     

    package

    {

        import starling.display.Quad;

        import starling.display.Sprite;

        import starling.events.Event;

        import starling.events.Touch;

        import starling.events.TouchEvent;

        import starling.events.TouchPhase;

       

        public class TouchDemo extends Sprite

        {

            private var _q:Quad;

           

            public function TouchDemo()

            {

                super();

               

                addEventListener(Event.ADDED_TO_STAGE, _onAdded);

            }

           

            private function _onAdded(e:Event):void

            {

                removeEventListener(Event.ADDED_TO_STAGE, _onAdded);

               

                // make a quad

                _q = new Quad(150,50,0xFF0000);

                addChild(_q);

               

                // listen for touch

                _q.addEventListener(TouchEvent.TOUCH, _onTouch);

               

            }

           

            private function _onTouch(e:TouchEvent):void

            {

                // get all touches

                const touches:Vector.<Touch> = e.getTouches(_q);

                // phase ending (finger release)?

                for each (var touch:Touch in touches)

                {

                    if (touch.phase == TouchPhase.ENDED)

                    {

                        trace("Touch ended on quad!");

                    }

                }

            }

        }

    }

     

    Obviously your XML needs renderMode set to "direct". That's just testing on an iPad resolution in portrait (for no specific reason).

     

    I converted that to an Actionscript Project (AIR desktop) and the only thing I changed in Main.as was waiting for Event.ENTER_FRAME instead of Event.ACTIVATE. Both trace "Touch has ended on quad!" as soon as I let my mouse up. This is tested in the AIR for iOS and AIR for Desktop simulator.

     

    There's no problem with TouchEvent working. You'll have to dig deeper in your controls code and see if any event propagation is being stopped. There's really no othe reason you wouldn't receive a TouchEvent if you registered it on your object properly.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 26, 2012 9:53 AM   in reply to alex.harrison

    To just test on desktop, change the Main.as class to listen for ENTER_FRAME which is pretty standard:

     

    Main.as:

     

    package

    {

        import flash.display.Sprite;

        import flash.events.Event;

        import flash.geom.Rectangle;

       

        import starling.core.Starling;

       

        [SWF(frameRate=60,width=768,height=1024)]

        public class Main extends Sprite

        {

            private var _starling:Starling; 

            public function Main()

            {

                addEventListener(Event.ENTER_FRAME, _onEnterFrame);

                Starling.multitouchEnabled = true;

            }

           

            protected function _onEnterFrame(event:Event):void

            {

                removeEventListener(Event.ENTER_FRAME, _onEnterFrame);

               

                // start starling, iPad portrait

                _starling = new Starling(TouchDemo, this.stage, new Rectangle(0,0,768,1024));

                _starling.start();

            }

        }

    }

     

    Changes are bolded. Nothing big, I just like to listen for ACTIVATE on mobile devices before proceeding, ENTER_FRAME on desktop. The Starling code is unchanged.

     

    I didn't mention but I did provide a multi-touch example. It's up to you to decide how to handle touches. When you register to receive TouchEvent.TOUCH your handler is going to get sprayed with tons of events.That's why I was getting all the touches (multitouch support) and checking to make sure the phase was TouchPhase.ENDED.

     

    If you throw a trace("TouchEvent: " + e); above that condition you'll see all the events sprayed at the event handler. It updates very fast as you move your finger (or mouse) as intended. For a desktop app however, you really have no need for multitouch so you can disable that and then you won't need to get a list of all the touches that happened running the for each () {} loop like I did.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 26, 2012 1:07 PM   in reply to alex.harrison

    Ah, the above example is Flash Builder but you could open a new AS3.0 document, save the above code to the filenames mentioned and set the document class to "Main" to try the examples. I'm just trying to see if your Starling is responding to touch events overall to isolate a Starling/Stage3D issue from any complex components.

     

    Also make sure that you're testing with the debugger (CTRL+SHIFT+ENTER) and that you've updated your AIR SDK and Flash Player to the latest version overlayed on Flash Pro.

     

    I myself still use Flash CS5.5 and build apps with Flash Builder. My CS5.5 launches FP 10.2 when I just use CTRL+ENTER. CS6 is probably updated to at least launch 11.x but as long as you overlayed FP11.5 and AIR3.5 you should be ok. To be sure, trace the version of Flash Player the debugger is running: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/system/Capabilities.html#version

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 28, 2012 8:02 AM   in reply to alex.harrison

    You're welcome and if you get any code snippits you're not sure of just open a new thread based on that content with the snippit and/or head over to the Starling forum. Stage3D is definitely a whole different animal, a bit difficult to diagnose. I'm glad touching is working in general so your SDK is functioning properly and you have a lead.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 29, 2012 7:40 AM   in reply to alex.harrison

    Ah mobile to desktop copying . That not only stops Starling but because Adobe unified Stage3D, StageVideo and the Display List in a single pass, that actually froze your entire app on losing focus. You can verify that by running a trace on a Timer. As soon as you run .stop() on a Starling instance (stop Stage3D from running present()) you'll see everything overall stops, no more traces from the timer, etc. Careful with that!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points