2 Replies Latest reply on Jun 30, 2011 8:43 AM by pauland

    Touch events conundrum/problem

    pauland Level 4

      I've been using Flash CS5.5 targeting the IOS platform (iPad).

      I have been writing a small application that relies on things being  dragged around - can't really say much more right now.

      I need to know when dragging starts, so on the thing that's being  dragged I add a listener for TouchEvent.TOUCH_BEGIN.

      I need to know when it's being moved, so the widget also has a listener  for TouchEvent.TOUCH_MOVE.

      And finally, I need to know when dragging stops, so the widget listens  for TouchEvent.TOUCH_END.

      Now mostly, everything goes OK, I get:

      TOUCH_BEGIN, followed by one or more TOUCH_MOVE, and finally a  TOUCH_END. Happiness.

      I have noticed that sometimes if I drag too fast and/or gently do a  swipe motion lifting my finger gently, the TOUCH_END doesn't seem to  happen, so the app doesn't know that the user has stopped dragging. For  the app, this is a problem because the user is allowed to position the  widget roughly and on TOUCH_END it should snap into place.

      Anyone else seen this?

      I can imagine a workaround using a timer to catch missing TOUCH_END  events, but it's a bit of a kludge.

      Paul

       

      Test case: I have created a very simple app with a symbol instance "square" which is simply a MovieClip containing a box shape and also on the stage I have a text field "countText". Dragging the square around gently means the numbers show multiple moves and matching begins and ends. Start dragging quickly and gently lifting the finger then the begin events then outnumber the end ones.

       

      On frame 1 I have the following code:

       

      stop();
      import flash.ui.*;
      import flash.events.TouchEvent;

       

      Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
      square.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchEvent);
      square.addEventListener(TouchEvent.TOUCH_MOVE, onTouchEvent);
      square.addEventListener(TouchEvent.TOUCH_END, onTouchEvent);
      var beginCount:uint=0;
      var moveCount:uint=0;
      var endCount:uint=0;

       

      function onTouchEvent(event:TouchEvent):void{
          switch (event.type){
              case TouchEvent.TOUCH_BEGIN:
                          beginCount++;
                          square.startTouchDrag(event.touchPointID);
                          break;
              case TouchEvent.TOUCH_MOVE:
                          moveCount++;
                          break;
              case TouchEvent.TOUCH_END:
                          endCount++;
                          square.stopTouchDrag(event.touchPointID);
                          break;
          }
          countText.text = "begin: "+beginCount+" move: "+moveCount+" end: "+endCount;
      }

        • 1. Re: Touch events conundrum/problem
          senc01a

          I pretty much have the same problem over here.

          I hope that someone posts a solution soon. I don't have this problem when I use the OpenExhibits framework for example.

          • 2. Re: Touch events conundrum/problem
            pauland Level 4

            I realised myself what has been happening.

             

            With the listener added to the component being dragged, there's a problem when the drag speed is too fast because the movement of the component being dragged can lag behind the finger. When this happens, the TOUCH_END  event may not be seen by the dragged object, because the finger is being raised from the tablet when the dragged object hasn't caught up with the movement of the finger so it doesn't catch the event. Basically the finger moves off the dragged component when the finger goes too fast.

             

            The solution has been to add the TOUCH_MOVE and TOUCH_END listeners to the stage.

             

            Paul