1 /** 2 * com.sekati.draw.Rectangle 3 * @version 1.0.5 4 * @author jason m horwitz | sekati.com 5 * Copyright (C) 2007 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.geom.Point; 10 11 /** 12 * Rectangle drawing utility. 13 */ 14 class com.sekati.draw.Rectangle { 15 16 /** 17 * Draw a rectangle in an existing clip 18 * @param mc (Movie Clip) target clip to draw in 19 * @param topLeft (Point) 20 * @param bottomRight (Point) 21 * @param fillColor (Number) hex fill, if undefined rectangle will not be filled 22 * @param fillAlpha (Number) fill alpha transparency [default: 100] 23 * @param strokeWeight (Number) border line width, if 0 or undefined no border will be drawn 24 * @param strokeColor (Number) hex border color 25 * @param strokeAlpha (Number) stroke alpha transparancy [default: 100] 26 * @return Void 27 * {@code Usage: 28 * var box:MovieClip = this.createEmptyMovieClip ("box", this.getNextHighestDepth ()); 29 * Rectangle.draw(box, new Point(50, 50), new Point(100, 100), 0xff00ff, 100, 1, 0x00ffff, 100); 30 * } 31 */ 32 public static function draw(mc:MovieClip, topLeft:Point, bottomRight:Point, fillColor:Number, fillAlpha:Number, strokeWeight:Number, strokeColor:Number, strokeAlpha:Number):Void { 33 var sw:Number = (!strokeWeight) ? undefined : strokeWeight; 34 var sc:Number = (isNaN( strokeColor )) ? 0x000000 : strokeColor; 35 var sa:Number = (isNaN( strokeAlpha )) ? 100 : strokeAlpha; 36 var fa:Number = (isNaN( fillAlpha )) ? 100 : fillAlpha; 37 38 var tl:Number = topLeft.x; 39 var bl:Number = topLeft.y; 40 var tr:Number = bottomRight.x; 41 var br:Number = bottomRight.y; 42 43 mc.clear( ); 44 mc.lineStyle( sw, sc, sa, true, "none", "square", "miter", 1.414 ); 45 if (!isNaN( fillColor )) { 46 mc.beginFill( fillColor, fa ); 47 } 48 mc.moveTo( tl, bl ); 49 mc.lineTo( tr, bl ); 50 mc.lineTo( tr, br ); 51 mc.lineTo( tl, br ); 52 if (!isNaN( fillColor )) { 53 mc.endFill( ); 54 } else { 55 mc.lineTo( bl, tl ); 56 } 57 } 58 59 private function Rectangle() { 60 } 61 }