Sprite Problem

Hi!

I’m trying to program a little tail that should follow a dot moving around the scene.
For this purpose I’ve meda a class in AS3 but I can’t get it to work. The idea is that the tail will receive a position and draw a line from the last received position to the new one.

I’ve got this code but I can’t make it work:

package {
 import flash.geom.Vector3D;
 import flash.geom.Point;
 import flash.display.Sprite;
    import flash.display.Graphics;
 public class Tail extends Sprite{
 
  private var lastPos:Vector3D;
  private var lines:Vector.<Sprite>;
  private var maxLength:int;
 
  public function Tail(maxLength:int, initialPos:Vector3D) : void {
 
   lines = new Vector.<Sprite>();
   this.maxLength = maxLength;
   this.lastPos = initialPos;
 
  }
  public function push(newPos : Vector3D) : void {
   var sprite = new Sprite();
 
   sprite.graphics.lineStyle(1,0xFF0000);
 
   var ps:Point; 
   ps = sprite.local3DToGlobal(lastPos);
   sprite.graphics.moveTo(ps.x, ps.y);
 
   ps = sprite.local3DToGlobal(newPos);
            sprite.graphics.lineTo(ps.x, ps.y);
 
   addChild(sprite);
 
   lines.push(sprite);
   if (lines.length > maxLength) removeChild(lines.shift());
  }
 
 }
}

And it is called from a fla with this code:

import flash.geom.Vector3D;
 
var v:Vector3D = new Vector3D(0,0,0);
var t:Tail = new Tail(5,v);
v = new Vector3D(50,80,0);
t.push(v);
v = new Vector3D(150,300,0);
t.push(v);
v = new Vector3D(200,80,0);
t.push(v);
 
this.addChild(t);

Any help would be much apreciated. Thanks!!