Curve animation


package  
{
 
 import flash.display.*;
 import flash.events.*;
 import flash.geom.*;
 /**
  * ...
  * @author Alex Lexcuk
  */
 public class DocMoveCurve extends Sprite
 {
  public var debSp:Sprite;
  public var lastM:Point = new Point();
  public var curM:Point = new Point();
  public var b:Point = new Point();
  public var speedStep:int = 10;
  public var curveArr:Vector.<Point> = new Vector.<Point>();
  public var persSp:Sprite;
  public var frameCount:int;
  public function DocMoveCurve() 
  {
   addChild(debSp = new Sprite());
   addChild(persSp = new Sprite());
   debSp.graphics.lineStyle(0);
   persSp.graphics.beginFill(0xFF0080);
   persSp.graphics.drawCircle(0, 0, 5);
   curveArr.push(new Point());
   stage.addEventListener(MouseEvent.CLICK, stageClickHandler);
   addEventListener(Event.ENTER_FRAME, enterFrameHandler);
  }
  public function enterFrameHandler(e:Event):void {
   persSp.x = curveArr[frameCount].x;
   persSp.y = curveArr[frameCount].y;
   frameCount++;
   if (frameCount >= curveArr.length) frameCount = 0;
  }
  public function stageClickHandler(e:MouseEvent):void {
   drawMousePath();
  }
  public function drawMousePath():void {
   var mx:Number = debSp.mouseX;
   var my:Number = debSp.mouseY;
   var bt:Point = new Point(lastM.x - b.x,lastM.y - b.y);
   var mt:Point = new Point(lastM.x - mx, lastM.y - my);
   bt.normalize( mt.length / 2);
   b = bt.add(lastM);
   
   debSp.graphics.moveTo(lastM.x, lastM.y);
   debSp.graphics.curveTo(b.x, b.y, mx, my);
   debSp.graphics.drawCircle(b.x, b.y, 4);
   
   curM = new Point(mx, my);
   addToArrPosCurve();
   lastM = new Point(mx, my);
  }
  public function addToArrPosCurve():void {
   var i:int;
   var p:Point = new Point();
   var lp:Point = lastM.clone();
   var ps:Point;
   
   for (i = 0; i <= 100; i++) {
    p.x = myCurveTo(lastM.x, b.x, curM.x, i / 100);
    p.y = myCurveTo(lastM.y, b.y, curM.y, i / 100);
    ps = p.subtract(lp);
    if (ps.length > speedStep) {
     curveArr.push(lp = p.clone());
     debSp.graphics.drawCircle(p.x, p.y, 4);
    }
   }
   
  }
  public function myCurveTo(n1:int, n2:int, n3:int, n4:Number):Number{
   return (1 - n4) * (1 - n4) * n1 + 2 * n4 * (1 - n4) * n2 + n4 * n4 * n3;
  }
 }
}

http://murmadillo.tut.su/m/doc-move-curve.swf