Skip navigation
Currently Being Moderated

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

May 1, 2012 3:55 PM

Tags: #as3.0 #actionscript3 #drag

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    

 
Replies
  • Currently Being Moderated
    May 1, 2012 4:50 PM   in reply to Riccardo Moschetti

    Try using e.currentTarget instead of e.target.  You might just be moving the innards of myImage and not myImage itself.

     
    |
    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