Skip to main content
Stationmaster_Porter
Participant
March 10, 2011
Question

Drag along a path?

  • March 10, 2011
  • 1 reply
  • 769 views

Hi you wonderful internet guys!

I want to create an object which can be clicked and dragged, but to follow a path rather than be free-moving.

Does anyone have a good way of doing this or know of a good tutorial which can help?

Cheers,

Porter.

This topic has been closed for replies.

1 reply

Inspiring
March 10, 2011

A lot depends upon what kind of path you desire. There are many different approaches that are good for this or that -- depending upon what you are trying to do.

One simple trick is to make a movieclip of the item moving along the path. Then stop() that clip. Once you start draging you figure how far along you are and use the gotoAndStop() to send the playhead to the part of the movie that reflects how the item would look if you were dragging it.

There are other tricks for describing paths with things like bezier curves and solving for x at y or y at x.

It really all depends upon your specific case.

Stationmaster_Porter
Participant
March 11, 2011

Thanks Rothrock,

I've tried playing with the gotoAndStop() using movieclips but thats not really what I'm after.

Maybe more along the lines of a scrollbar, where the  object.y  moves up and down identical to the  mouse.y  but the x value is dictated by the path (i.e. fixed)

I'll try making a button which follows the mouse but using only one co-ordinate and see what happens...


Cheers,

Porter.