/** * com.sekati.draw.Polygon * @version 1.0.0 * @author jason m horwitz | sekati.com * Copyright (C) 2008 jason m horwitz, Sekat LLC. All Rights Reserved. * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php */ import com.sekati.except.IllegalArgumentException; /** * Polygon drawing utility. */ class com.sekati.draw.Polygon { /** * Draw a polygon into an existing clip * @param mc (Movie Clip) target clip to draw in * @param points (Array) Array of Points * @param fillColor (Number) hex fill, if undefined rectangle will not be filled * @param fillAlpha (Number) fill alpha transparency [default: 100] * @param strokeWeight (Number) border line width, if 0 or undefined no border will be drawn * @param strokeColor (Number) hex border color * @param strokeAlpha (Number) stroke alpha transparancy [default: 100] * @return Void * {@code Usage: * var box:MovieClip = this.createEmptyMovieClip ("box", this.getNextHighestDepth ()); * Polygon.draw( polyMc, pointArray, 0xff00ff, 100, 1, 0x00ffff, 100 ); * } */ public static function draw(mc:MovieClip, points:Array, fillColor:Number, fillAlpha:Number, strokeWeight:Number, strokeColor:Number, strokeAlpha:Number):Void { var sw:Number = (!strokeWeight) ? undefined : strokeWeight; var sc:Number = (isNaN( strokeColor )) ? 0x000000 : strokeColor; var sa:Number = (isNaN( strokeAlpha )) ? 100 : strokeAlpha; var fa:Number = (isNaN( fillAlpha )) ? 100 : fillAlpha; if (points.length < 3) { throw new IllegalArgumentException( Polygon, "@@@ com.sekati.draw.Polygon.draw() Error: method requires a points array argument containing at least 3 Point objects.", arguments ); } mc.clear( ); mc.lineStyle( sw, sc, sa, true, "none", "square", "miter", 1.414 ); if (!isNaN( fillColor )) { mc.beginFill( fillColor, fa ); } mc.moveTo( points[0].x, points[0].y ); var len:Number = points.length; for(var i:Number = 0; i < len ; i++) { mc.lineTo( points[i].x, points[i].y ); } mc.lineTo( points[0].x, points[0].y ); if (!isNaN( fillColor )) { mc.endFill( ); } } }