views:

55

answers:

3

Same as the question: I need to drag a component along a programmatically drawn path composed by different kinds of graphic, like lines, curves, etc.

I've already googled it, but with no success. Any ideas? thanks!

A: 

Will this work? http://www.pixeldigest.com/followthepath.html

mkoistinen
nope, as I said I need a programmatically drawn path (using the Graphics class)
Alberto M
+1  A: 

The following is say for a linearly curved path drawn by you. You can use similar method for any direction.

  • Add an Event listener for click. (That starts drag)

  • Track the user's mouse along x direction for example.

  • Keep plotting the component's x & y as Mouse x changes with respect to the drawn path's x.

  • Stop relocating as user leaves the mouse

Start with this if possible & be back with code if you get doubts.

loxxy
yeah, that's what I was pretty much thinking..I was hoping in something native, but I guess there's no such a thing :) I'll give it a try and get back to you! thanks a lot
Alberto M
ok, I know that this is pretty much math, but I can't figure it out: how can I calculate the y position of a line knowing the x?? but more than that, how can I do that with a curve?
Alberto M
If the curve is drawn from a mathematical function, then it will be in the form y = function(x).
mkoistinen
I didn't explain it well, and I just realized it :) my path can be composed by different kind of drawings, like lines, curves, drawings by hands, and so on..so my new question is: how can I get a graphics' given point position?
Alberto M
+1  A: 

If your drawing part is complete then You can use two dimensional ByteArray. The size of the ByteArray will be the size of your stage, this two-dimensional array will be set to zero, means all your stage locations are set to zero. When any curve or line is drawn , set those locations to one. Now you know at-least where your object can move, the valid locations are those which are set to one. Now the second the part is how to move an object on the valid path or location using mouse or keyboard.

You will be using Event.EnterFrame for smooth and fast movement of the object,

1--using keyboard. use up key to move object to upper location if that position or location is set to one else the object will not move Up, same for others.

2-- using mouse move event, detect MouseY position for moving UP or DOWN w.r.t current position of MouseY , and move it respectively if location is set to one.

Hope, this will guide you in right direction...

Muhammad Irfan
these past few days I've tried to implement this, but before I go further.. what if to the same x or y are related more than one y or x ? (eg. in the case of a line drawn under or beside another)
Alberto M
Well if the user moves the object, you do not need worry. Else you can use some conditions, if(myStageloc[40][40]==1){ myStageloc[40][40]=2; concide_point[0][0] = myStageloc[40][41]; concide_point[0][1]=myStageloc[39][40]; } so you need to double check that if(myStageloc[40][40]==2) go to concide_point[0][0] .. means you have to build some logic to check that if it overrides.
Muhammad Irfan