3 Replies Latest reply: May 2, 2012 11:30 PM by Riccardo Moschetti RSS

    Cannot re-position image via x and y properties after dragging it with startDrag / stopDrag

    Riccardo Moschetti

      Hello,

      I am using AS 3 for mobile development but I believe this is related to AS in general do I'll humbly post my question here.

      Here is my enviroment

       

      Mac OS X Lion

      FB 4.6

      AIR 3.2

       

      I have this problem:

      In order to move an image on the screen, I use startDrag's and stopDrag's equivalents for mobile, meaning startTouchDrag and stopTouchDrag,

      This works fine and smoothly, except that after the dragging stops I cannot further move the image on the screen by changing its x and y coordinates.

       

      x and y, after the startDrag, seem to have values that are completely independent of where the image actually is on the screen. If I change them, the image's position does not change.

       

      this is the MXML code to define the image

       

      <s:Group id="totalGroup" width="100%" height="100%" doubleClick="resizePic(event)" >

          <s:Image id="myImage" smoothingQuality="high"  x="100" y="200" />

          <s:Button id="myButton" label="Re-position" click="myButton_Click(event)" />

      </s:Group>

       

      This is the AS3 code: at init, I link touch events (begin, end) to two functions that start and stop drag

       

          myImage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);

        myImage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);

        myImage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);

       

       

        function onTouchBegin(e:TouchEvent) {

        e.target.startTouchDrag(e.touchPointID);

        trace ("touch BEGIN X: "+myImage.x + " Y: "+myImage.y);

          }

       

        function onTouchEnd(e:TouchEvent) {

        e.target.stopTouchDrag(e.touchPointID);

        trace ("touch END X: "+myImage.x + " Y: "+myImage.y);

                                      }

       

      the image moves OK, but the X and Y coordinates are not the coordinates on the screen: they're fixed and do not mirror where the image actually IS on the screen.

       

      Then I have a button that does this:

       

      function myButton_Click(event:MouseEvent) {

      myImage.x=100;

      myImage.y=200;

      trace ("Correctly in here but myImage stays there");

      }

       

      Except that this does not do anything (albeit no exception is given) and the image stays exactly where it was when I last dragged it!

       

      Can Anyone help?

      thanks!

      Riccardo