Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash 8: Moving and aligning an object along a path using startDrag 1

Status
Not open for further replies.

artISgarbage

IS-IT--Management
Mar 6, 2006
1
US
This is my first post here, I hope I can find some help!

i'm busting my brains...

I am trying to build a navigation header for one of my projects right now... the header has a nice curve to it, and I want to get my nav buttons to ease-and-follow the x-coordinate of the mouse cursor, but still snap to the curve...

This is the 1st frame actionscript to get the object (follow) to follow-and-ease with the x-coordinate of the mouse:

mouse_x = _xmouse;
setProperty (_root.follow, _x, mouse_x+((getProperty(_root.follow,_x)-mouse_x)/2));

That works just fine for moving along one axis, but no matter what tweaks I try... I simply cannot get modify this actionscript to get my object to snap to a motion guide. I suppose I could define the path with actionscript, but I am unfamiliar with this technique and I am on a deadline for this project. The only tutorial I found for this method is highly in depth, complex and honestly I just need to bang this out (
I tried cheating the actionscript by applying a clip inside of the object (follow), locking it to a motion guide and giving it a similar actionscript to the one above setting a variable for the sub-objects' y-position... No dice.

If somebody out there has done something similar and could refer me to a tutorial or FLA I would be IMMENSLY appreciative. Any thoughts at all would be great. Many thanks! ~Anthony
 
The most elegant way to achieve your goal is to define your motion guide path in a mathematical equation. If you can do that then it is easy to determine the MovieClip's _y position by just applying the equation.

Or you can use the following hack I've just put together:

1. Create a MovieClip, which will follow your mouse along the path. I called it "mcBall" in this example.
2. Create a motion path, but make it as filled shape. I made a shape which is basically a stage wide rectangle but the top side is curved - a bit like a side view of ocean wave, if you see what I mean. Convert it as a MovieClip. I called it "mcPath".
3. The script.

[tt]//Main timeline
onEnterFrame = function ():Void {
mcBall._x += (_xmouse-mcBall._x)/4;
for (var i = 0; i<Stage.height; i++) {
if (mcPath.hitTest(mcBall._x, i, true)) {
mcBall._y = i;
break;
}
}
};
//
stop();
//[/tt]

That's it - mcBall will follow your mouse along the top of the mcPath. You can set the mcPath's alpha to 0 to make it invisible.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top