Draw a Line from MC to MC

Hey there, I have some code which works to the point where I generate random squares onto the stage, then in their order of birth, I draw a line from one box to the next. It works. BUT!!! it messes up. Check out the code…

var mcArray:Array = new Array();

for (var i:int = 0; i<5; i++)
{
    var mc:square = new square();//exports from library
    mc.x = Math.random()*500;
    mc.y = Math.random()*200;
    mc.name = "square"+i;
    mc.id = i;
    mcArray.push(mc);
    
    mc.addEventListener(Event.ENTER_FRAME, connect);
    addChild(mc);
}
function connect(e:Event):void
{
    var me:int = e.target.id;
    var you:int = me + 1; // This seems to cause TypeError: Error #1009: Cannot access a property or method of a null object reference.
    var mc:MovieClip = MovieClip(mcArray[me]);
    var to:MovieClip = MovieClip(mcArray[you]);
    
    mc.y += Math.random()*2; // for such a short amount to move, the performance is very jerky
    
    // graphics.clear(); addind clear removes ALL line graphics
    graphics.lineStyle(1,0x000FFF);
    graphics.moveTo(mc.x,mc.y);
    graphics.lineTo(to.x,to.y);
    
    if(mc.y > stage.stageHeight/2)
    {
        mc.removeEventListener(Event.ENTER_FRAME, connect); // ONE mc ALWAYS escapes
    }
}

I have written the problem areas inside the code. This is elementary stuff watson. but ■■■■, it’s been troubling me.:rock: Can anyone help me out how I can clean this stuff up!?