Drawing lines (polygons)

First draw a line from 0,0 to 100,100 and make it a movieclip. Rightclick the new movieclip in the library and open its linkage paramter panel. Activate "Export this symbol" and enter the name "line". frame 1: //our function to draw lines from an reverse array of points //the array of points is in reverse order to make processing faster //initialise it something like that pts = [pt100y, pt100x,.... ,pt1y,pt1x] //the depth parameter is the starting point for depth //the count of lines is returned to make it easier to delete the lines function drawPolygon(pts, depth){ var i = pts.length, n, x, y; x = pts[--i]; y = pts[--i]; while(i > 0){ n = "l" + depth; attachMovie("line", n, depth++); with(eval(n)){ _x = x; _y = y; x = pts[--i]; y = pts[--i]; _xscale = x - _x; _yscale = y - _y; } } return depth } //sometimes you want to get rid of all that funky polygons function deletePolygon(depth, count){ while(--count >= depth) this["l" + count].removeMovieClip(); } //example: draw and delete rectangle points = new Array(100,100,200,100,200,200,100,200,100,100); d = drawPolygon(points, 200); //... //deletePoygon(200,d);
Add comment
Home