# Sprite Problem

**URL:** https://forum.kirupa.com/t/sprite-problem/298163
**Category:** Uncategorized
**Created:** [October 14, 2009, 5:06pm UTC](https://forum.kirupa.com/t/sprite-problem/298163 "2009-10-14T17:06:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![cesco](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@cesco](https://forum.kirupa.com/u/cesco)
#### Post date: [October 14, 2009, 5:06pm UTC](https://forum.kirupa.com/t/sprite-problem/298163/1 "2009-10-14T17:06:21Z")

</div>

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:

```auto
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:

```auto
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!!
