# Drawing Lines Between Objects Stored In Array

**URL:** <https://forum.kirupa.com/t/drawing-lines-between-objects-stored-in-array/320518>\
**Category:** flash\
**Created:** [March 25, 2011, 8:04pm UTC](https://forum.kirupa.com/t/drawing-lines-between-objects-stored-in-array/320518 "2011-03-25T20:04:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CCG1993](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@CCG1993](https://forum.kirupa.com/u/CCG1993)\
**Post date:** [March 25, 2011, 8:04pm UTC](https://forum.kirupa.com/t/drawing-lines-between-objects-stored-in-array/320518/1 "2011-03-25T20:04:04Z")

</div>

Basically I am completely stuck…:puzzled:

I’m trying to draw a line between circles stored in an array. I have a button on the stage which adds another circle to the stage. My issue is I cannot draw a line between the most recent circle added to the array and the one that will be added next.

It is a bit complicated and I’m not an experienced programmer by any stretch of the imagination.:emb:

Anyway, here’s my code:

```auto
var pointArray:Array = new Array()
var currentPoint:Number = pointArray.length
var thePoint:MovieClip = new drawPoint() 
addChild(thePoint)
pointArray.push(thePoint)
thePoint.x = stage.stageWidth/2
thePoint.y = stage.stageHeight/2
thePoint.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag)
thePoint.addEventListener(MouseEvent.MOUSE_UP, endDrag)
thePoint.addEventListener(Event.ENTER_FRAME, drawShapes)
addPointButton.addEventListener(MouseEvent.MOUSE_UP, addPoint)
function addPoint(event:MouseEvent):void{
 
 var thePoint:MovieClip = new drawPoint()
 addChild(thePoint)
 pointArray.push(thePoint)
 thePoint.x = stage.stageWidth/2
 thePoint.y = stage.stageHeight/2
 thePoint.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag)
 thePoint.addEventListener(MouseEvent.MOUSE_UP, endDrag)
 thePoint.addEventListener(Event.ENTER_FRAME, drawShapes)
}

function beginDrag(event:MouseEvent):void{
 event.target.startDrag()
}
function endDrag(event:MouseEvent):void{
 event.target.stopDrag()
}
function drawShapes(event:Event):void{
 for (var i =0; i < pointArray.length; i++){
  var shape:Sprite = new Sprite()
  addChild(shape)
  shape.graphics.beginFill(0x000000)
  shape.graphics.moveTo(pointArray[currentPoint].x, pointArray[currentPoint - 1].y)
  shape.graphics.lineTo(pointArray[currentPoint].x, pointArray[currentPoint].y)
  
 }
}

```

Currently I am getting a TypeError: Error# 1010.

Thankyou in advance.

CCG1993.
