• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
May 01, 2012 May 01, 2012

Copy link to clipboard

Copied

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    

TOPICS
ActionScript

Views

701

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 01, 2012 May 01, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2012 May 01, 2012

Copy link to clipboard

Copied

Thanks Ned, this helps with the tracing of the coordinates but does not change the issue that x and y re-assigning is not sufficient to move the image after dragging. 

I changed the function's code to:

e.currentTarget.startTouchDrag(e.touchPointID);

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

and now the trace gives the correct values (x and y on the screen)

However, when dragging is over,  a button is clicked and these actions (x and y re-assignment)  are performed, there is no change in the image's position

myImage.x=100;

myImage.y=200

[or:

event.currentTarget.x=100;

event.currentTarget.y=200:

x and y positioning works perfectly if the image has been moved on the screen by some other method that is not startTouchDrag / stopTouchDrag

apparently, before being able to change x and y of an image that has been dragged, some method of the same image must be called?



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 02, 2012 May 02, 2012

Copy link to clipboard

Copied

LATEST

OK now I understand what was wrong...

And am very ashamed.

the button and image were very close.

I have big hands. when i clicked on the button, i also touched the image,which went into drag mode

and - when in drag mode - can't be repositioned by changing x and y...

sorry and thanks for inspiration!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines