PDA

View Full Version : Create Polygon from Array?


brewthom
06-30-2009, 06:04 PM
I'm trying to figure out how to draw a polygon from an array. I've found a few examples, one which the author says works, but am not getting anything to appear. I've traced the array (it's registering) and am getting no errors. Help appreciated.


//called from constructor
polygon(thisArray);

public function polygon(arr:Array):void{

trace (arr) ; //ok
var sh:Sprite= new Sprite();

sh.graphics.lineStyle(1,0xCCCCCC);
sh.graphics.moveTo(arr[0],arr[1]);
sh.graphics.beginFill(0xFF9900, 1);

for (var i=0; i<arr.lenght; i+=2){//
if (i==0){
sh.graphics.moveTo(arr[i], arr[i+1]);
}else{
sh.graphics.lineTo(arr[i],arr[i+1]);

if (i==6 || i==2){

sh.graphics.lineStyle(1,0xCCCCCC,0);
}else{
sh.graphics.lineStyle(1,0xCCCCCC);
}
}

}


sh.graphics.endFill();
addChild(sh);



}

brewthom
06-30-2009, 07:03 PM
FOUND the typo. (length, not lenght). How the heck did that not throw an error?