..... for (var i = 1; i < Xmid.length; i++) { this.curveTo(Xmid[i],Ymid[i],Xpoint[i],Ypoint[i]); } if(closed){ this.endFill(); } delete Xmid; .....