12 Replies Latest reply: Nov 29, 2012 7:40 AM by sinious RSS

    SimController - Touch and gesture not working

    alex.harrison Community Member

      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

        • 1. Re: SimController - Touch and gesture not working
          sinious CommunityMVP

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

          • 2. Re: SimController - Touch and gesture not working
            alex.harrison Community Member

            Hi Sinious,

             

            I have event handlers attached to various buttons. These work as expected when I run the app on devices (iPod, iPad, etc).

            But in the Simcontroller nothing happens when I click on any buttons using the touch simulator.

            If I switch to compile with Air for desktop rather than for iOS or Android then the app runs outside of the Simcontroller and the buttons function as normal but from mouse click rather than touch.

             

            cheers,

            Alex

            • 3. Re: SimController - Touch and gesture not working
              sinious CommunityMVP

              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.

              • 4. Re: SimController - Touch and gesture not working
                alex.harrison Community Member

                I mean I just tested it when compiling for desktop to see if it would work.

                I'll have to come back to this tomorrow when I get back in to the office!

                • 5. Re: SimController - Touch and gesture not working
                  sinious CommunityMVP

                  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.

                  • 6. Re: SimController - Touch and gesture not working
                    alex.harrison Community Member

                    Hi Sinious, thanks for your reply.

                    I will try running your code when I am back in the office tomorrow.

                    But, I am pretty sure that my Starling code is not at fault. It works fine when I compile and run it on an actual device. I've tried it on an iPad 1, iPad 3, iPod 5, Samsung Galaxy Tab and a Kindle fire HD. On all of those devices the touch handling works with no problems at all.

                    It's only when I do a straight forward 'Ctrl-Enter' to test within the Flash IDE and it loads the Sim Controller that I find the buttons don't register touches. In fact, thinking about it, specifically what is not working is that Starling buttons are not reacting to touch events. I didn't actually try for example adding my own touch event listeners to an image or sprite. So that is another avenue I could explore tomorrow.

                     

                    cheers for the help so far,

                    Alex

                    • 7. Re: SimController - Touch and gesture not working
                      sinious CommunityMVP

                      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/flash/system/Capabiliti es.html#version

                      • 8. Re: SimController - Touch and gesture not working
                        alex.harrison Community Member

                        Ok, cool - I'll let you know how I get on tomorrow!

                        thanks,

                        Alex

                        • 9. Re: SimController - Touch and gesture not working
                          alex.harrison Community Member

                          Hi Sinious,

                          I was off sick yesterday, but I just tried your code this morning and found that it does work on my system - I get some output traced when I click on the quad.

                          So there must be something else happening in my own code that is causing the problem.

                          thanks for your help.

                          Alex

                          • 10. Re: SimController - Touch and gesture not working
                            sinious CommunityMVP

                            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.

                            • 11. Re: SimController - Touch and gesture not working
                              alex.harrison Community Member

                              For the record I just discovered what was causing my issue. I had copied the code of my document class from the Starling demo for mobile. It included the following lines that cause starling to pause if it loses focus:

                               

                              NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE,

                                              function (e:Event):void { mStarling.start(); });

                                         

                                          NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE,

                                              function (e:Event):void { mStarling.stop(); });

                               

                              This gets triggered whenever the Simcontroller is activated, which effectively prevents any touch events being processed! My workaround will be to only activate those lines if not running in the Flash IDE.

                               

                              cheers for the help,

                              Alex

                              • 12. Re: SimController - Touch and gesture not working
                                sinious CommunityMVP

                                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!