Create Polygon from Array?

By brewthom | Jun 30, 2009

actionscript3

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.

Code:

//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);
                                               
                                       
                                       
                        }


actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0