Some days ago I had to do a Flash application where the user was able to select an image area by dragging some points around. The points should be anchors to create curves that pass through those points.
My first thought was that I wouldn’t have problems by using the curveTo method of the MovieClip class as long this method uses 3 points to create a curve, what was exactly what I needed.
The problem is that this method uses the Bézier formula to create the curve, and the Bézier curve does not pass through the second point, as you can see above:
I strong believe that I wasn’t the first one to have this frustration trying to create a curve on Flash, because that I decided to post the solution.

The formula above is the Bézier formula. Using my second point as B(t), 0.5 as t (the middle of the curve) and isolating the P2 I came to this code:
p3.x = (0.25 * p0.x + 0.25 * p2.x - p1.x) / -0.5; p3.y = (0.25 * p0.y + 0.25 * p2.y - p1.y) / -0.5; moveTo(p0.x, p0.y); curveTo(p3.x, p3.y, p2.x, p2.y);
P0, P1, P2 are the 3 points used to create the curve, P3 is the generated point to replace the P2 on the curveTo method.
Here is the result:
I hope it helps someone!
7 comments ↓
Hi, nice article.
BTW: the beziere formula ist supported natively by the player (from 9 up) in the fl.motion package. Search livedocs for "BezierSegment". Helps to speed up your app and keep code short
Thanks so much, this is just what I needed!
You're welcome
Thank you – been looking for days for something like this.
BTW, your swf's dont show up anymore.
Sorry, I had a problem with my old server so I lost that files and I don't have the source anymore. But I'm glad that it helped you.
Awesome! thank you so much!
Howdy every one, nice website I have found It very accessible and it has helped me a lot
I hope to be able to give something back and guide other users like this forum has helped me
_________________
unlock iphone 4.0
Leave a Comment