http://img171.images..p?image=curve8eq.swf
That is what you'll be making.
So one day I set out to get a better understanding of the curveTo() command. Here's what I knew already.
*The curve starts at the drawing point (set with the moveTo command, see AS: API for more info)
*It goes to the anchor point. mc.curveTo(control x, control y, ANCHOR X, ANCHOR Y)
*The curve is defined by the control point, it goes half way to the control point
So here we have our curve.
createEmptyMovieClip("sq1", 3);
d1 = false;
d2 = false;
d3 = false;
with (sq1) {
lineStyle(2, 0x000000, 100);
beginFill(0xff0000, 70);
moveTo(-5, -5);
lineTo(5, -5);
lineTo(5, 5);
lineTo(-5, 5);
lineTo(-5, -5);
endFill;
_x = 100;
_y = 200;
}
duplicateMovieClip(sq1, "sq2", 6);
duplicateMovieClip(sq1, "sq3", 5);
createEmptyMovieClip("curve", 1);
sq2._x = 275;
sq2._y = 100;
sq3._x = 450;
sq3._y = 200;
_root.onMouseDown = function() {
if (sq1.hitTest(_xmouse, _ymouse, true)) {
d1 = true;
}
if (sq2.hitTest(_xmouse, _ymouse, true)) {
d2 = true;
}
if (sq3.hitTest(_xmouse, _ymouse, true)) {
d3 = true;
}
};
_root.onMouseUp = function() {
d1 = false;
d2 = false;
d3 = false;
};
_root.onEnterFrame = function() {
if (d1) {
sq1._x = _xmouse;
sq1._y = _ymouse;
} else if (d2) {
sq2._x = _xmouse;
sq2._y = _ymouse;
} else if (d3) {
sq3._x = _xmouse;
sq3._y = _ymouse;
}
curve.clear();
curve.lineStyle(3, 0x000000, 100);
curve.moveTo(sq1._x, sq1._y);
curve.curveTo(sq2._x, sq2._y, sq3._x, sq3._y);
};
All this does is basically make 3 points, and curve them. Click and drag the squares to see how the curve works.
Next in my experiments, I wanted to find out what it meant by the curve going half way to the control point. Through a little trial and error, I discovered that a line from the midpoint of the 2 anchor points to the control point is bisected equally by the curve.
I won't post code for this right now, as it is almost the same code, with a minor adjustment.
Next, I decided to find the exact point where the line intersected the curve and put a box there. Simple to do, it is just the midpoint of the line. Easy enough to do. It also made it easy for my next step.
Now, I made the box in the middle draggable too. Using some simple geometry, particularly slope, I could make it work like I wanted. Here's the code, but before you just go and copy the code into a flash, try to make it yourself. It will help you better understand the curveTo function.
createEmptyMovieClip("sq1", 3);
d1 = false;
d2 = false;
d3 = false;
d4 = false;
with (sq1) {
lineStyle(2, 0x000000, 100);
beginFill(0xff0000, 70);
moveTo(-5, -5);
lineTo(5, -5);
lineTo(5, 5);
lineTo(-5, 5);
lineTo(-5, -5);
endFill;
_x = 100;
_y = 200;
}
duplicateMovieClip(sq1, "sq2", 6);
duplicateMovieClip(sq1, "sq3", 5);
duplicateMovieClip(sq1, "sq4", 4);
createEmptyMovieClip("curve", 1);
createEmptyMovieClip("line", 2);
sq2._x = 275;
sq2._y = 100;
sq3._x = 450;
sq3._y = 200;
_root.onMouseDown = function() {
if (sq1.hitTest(_xmouse, _ymouse, true)) {
d1 = true;
}
if (sq2.hitTest(_xmouse, _ymouse, true)) {
d2 = true;
}
if (sq3.hitTest(_xmouse, _ymouse, true)) {
d3 = true;
}
if (sq4.hitTest(_xmouse, _ymouse, true)) {
d4 = true;
}
};
_root.onMouseUp = function() {
d1 = false;
d2 = false;
d3 = false;
d4 = false;
};
_root.onEnterFrame = function() {
if (d1) {
sq1._x = _xmouse;
sq1._y = _ymouse;
} else if (d2) {
sq2._x = _xmouse;
sq2._y = _ymouse;
} else if (d3) {
sq3._x = _xmouse;
sq3._y = _ymouse;
} else if (d4) {
sq4._x = _xmouse;
sq4._y = _ymouse;
xdist = sq4._x-((sq1._x+sq3._x)/2);
ydist = sq4._y-((sq1._y+sq3._y)/2);
sq2._x = sq4._x+xdist;
sq2._y = sq4._y+ydist;
}
curve.clear();
curve.lineStyle(3, 0x000000, 100);
curve.moveTo(sq1._x, sq1._y);
curve.curveTo(sq2._x, sq2._y, sq3._x, sq3._y);
curve.lineTo(sq2._x, sq2._y);
curve.lineTo(sq1._x, sq1._y);
curve.lineTo(sq3._x, sq3._y);
line.clear();
line.lineStyle(1, 0x000000, 100);
line.moveTo(sq2._x, sq2._y);
line.lineTo((sq1._x+sq3._x)/2, (sq3._y+sq1._y)/2);
sq4._x = (((sq1._x+sq3._x)/2)+sq2._x)/2;
sq4._y = (((sq1._y+sq3._y)/2)+sq2._y)/2;
};
~GG Out.