1  /**
     2   * com.sekati.draw.Polygon
     3   * @version 1.0.0
     4   * @author jason m horwitz | sekati.com
     5   * Copyright (C) 2008  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8  
     9  import com.sekati.except.IllegalArgumentException;
    10  
    11  /**
    12   * Polygon drawing utility.
    13   */
    14  class com.sekati.draw.Polygon {
    15  
    16  	/**
    17  	 * Draw a polygon into an existing clip
    18  	 * @param mc (Movie	Clip) target clip to draw in
    19  	 * @param points (Array) Array of Points
    20  	 * @param fillColor (Number) hex fill, if undefined rectangle will not be filled
    21  	 * @param fillAlpha (Number) fill alpha transparency [default: 100]
    22  	 * @param strokeWeight (Number) border line width, if 0 or undefined no border will be drawn
    23  	 * @param strokeColor (Number) hex border color 
    24  	 * @param strokeAlpha (Number) stroke alpha transparancy [default: 100]
    25  	 * @return Void
    26  	 * {@code Usage:
    27  	 * 	var box:MovieClip = this.createEmptyMovieClip ("box", this.getNextHighestDepth ());
    28  	 * 	Polygon.draw( polyMc, pointArray, 0xff00ff, 100, 1, 0x00ffff, 100 );
    29  	 * }
    30  	 */	
    31  	public static function draw(mc:MovieClip, points:Array, fillColor:Number, fillAlpha:Number, strokeWeight:Number, strokeColor:Number, strokeAlpha:Number):Void {
    32  		var sw:Number = (!strokeWeight) ? undefined : strokeWeight;
    33  		var sc:Number = (isNaN( strokeColor )) ? 0x000000 : strokeColor;
    34  		var sa:Number = (isNaN( strokeAlpha )) ? 100 : strokeAlpha;
    35  		var fa:Number = (isNaN( fillAlpha )) ? 100 : fillAlpha;
    36  
    37  		if (points.length < 3) {
    38  			throw new IllegalArgumentException( Polygon, "@@@ com.sekati.draw.Polygon.draw() Error: method requires a points array argument containing at least 3 Point objects.", arguments );	
    39  		}
    40  				
    41  		mc.clear( );
    42  		mc.lineStyle( sw, sc, sa, true, "none", "square", "miter", 1.414 );
    43  		if (!isNaN( fillColor )) {
    44  			mc.beginFill( fillColor, fa );
    45  		}
    46  		mc.moveTo( points[0].x, points[0].y );
    47  		var len:Number = points.length;
    48  		for(var i:Number = 0; i < len ; i++) {
    49  			mc.lineTo( points[i].x, points[i].y );
    50  		}
    51  		mc.lineTo( points[0].x, points[0].y );
    52  		if (!isNaN( fillColor )) {
    53  			mc.endFill( );
    54  		}	
    55  	}
    56  }
    57