Packageorg.aswing.graphics
Classpublic class Graphics2D

Encapsulate and enhance flash.display.graphics drawing API.
To draw with this API, you need to create a pen. To fill an area with this API, you need to create a brush.
You can find sampe usage of this api in the test package which will come with the source package.

Here is an sample on how to use the org.aswing.grphics package to draw stuff
 
    var mySprite:Sprite = new Sprite();
    g = new Graphics2D(mySprite.graphics);
   var color:ASColor = new ASColor();
   var matrix:Matrix = new Matrix();
   matrix.createGradientBox(100,100,90/(Math.PI),200,200);
   
   
   var pen:Pen = new Pen(2,color.getRGB());
   g.drawLine(pen,0,0,100,100);
    
    var gpen:GradientPen = new GradientPen(1,GradientType.LINEAR,[0xff00ff,0x00ff00,0xffff00],[1,1,1],[0,200,255],matrix);
   g.drawLine(gpen,400,100,500,500);
   
   var gBrush:GradientBrush= new GradientBrush(GradientType.LINEAR,[0xff00ff,0x00ff00,0xffff00],[1,1,1],[0,200,255],matrix);
   var sBrush:SolidBrush = new SolidBrush(ASColor.HALO_BLUE.getRGB(),0.3);
   var bBrush:BitmapBrush = new BitmapBrush(new BitmapData(50,50,false,0xffff00));
   
   g.fillEllipse(gBrush,100,100,300,200);
   g.fillRectangle(sBrush,100,100,100,100);
   g.fillRectangle(bBrush,0,0,50,50);
 
    addChild(mySprite);
 

See also

org.aswing.graphics


Protected Properties
 PropertyDefined by
  target : Graphics
Graphics2D
Public Methods
 MethodDefined by
  
Graphics2D(target:Graphics)
Constructor take instance of flash.display.Graphics as parameter.
Graphics2D
  
beginDraw(pen:IPen):void
Start to draw lines with pen
Graphics2D
  
beginFill(brush:IBrush):void
Start to fill a closed area with brush
Graphics2D
  
circle(centerX:Number, centerY:Number, radius:Number):void
Paths a circle
Graphics2D
  
clear():void
Clears the graphics contexts drawn on the target Graphics.
Graphics2D
  
curveTo(controlX:Number, controlY:Number, anchorX:Number, anchorY:Number):void
Paths a curve
Graphics2D
  
drawCircle(pen:IPen, centerX:Number, centerY:Number, radius:Number):void
Draws a circle.
Graphics2D
  
drawEllipse(pen:IPen, x:Number, y:Number, width:Number, height:Number):void
Draws a ellipse.
Graphics2D
  
drawLine(p:IPen, x1:Number, y1:Number, x2:Number, y2:Number):void
Draw a line between the points (x1, y1) and (x2, y2) in the target Graphics.
Graphics2D
  
drawPolygon(pen:Pen, points:Array):void
Draws a polygon.(close figure automaticlly)
Start to draw a ploygon with the points[0] as the start point and go through all the points in the array then go back to the points[0] end it as a closed path.
Graphics2D
  
drawPolyline(p:IPen, points:Array):void
Draws a polyline.
Graphics2D
  
drawRectangle(pen:IPen, x:Number, y:Number, width:Number, height:Number):void
Draws a rectange.
Graphics2D
  
drawRoundRect(pen:IPen, x:Number, y:Number, width:Number, height:Number, radius:Number, trR:Number = -1, blR:Number = -1, brR:Number = -1):void
Draws a round rectangle.
Graphics2D
  
ellipse(x:Number, y:Number, width:Number, height:Number):void
Paths an ellipse.
Graphics2D
  
endDraw():void
Stop drawing
Graphics2D
  
endFill():void
Stop filling a closed area with brush
Graphics2D
  
fillCircle(brush:IBrush, centerX:Number, centerY:Number, radius:Number):void
Fills a circle.
Graphics2D
  
fillCircleRing(brush:IBrush, centerX:Number, centerY:Number, radius1:Number, radius2:Number):void
Fills a circle ring.
Graphics2D
  
fillCircleRingWithThickness(brush:IBrush, centerX:Number, centerY:Number, radius:Number, thickness:Number):void
Fills a circle ring with a specified thickness.
Graphics2D
  
fillEllipse(brush:IBrush, x:Number, y:Number, width:Number, height:Number):void
Fills a rectange.
Graphics2D
  
fillEllipseRing(brush:IBrush, centerX:Number, centerY:Number, width1:Number, height1:Number, width2:Number, height2:Number):void
Fill a ellipse ring.
Graphics2D
  
fillEllipseRingWithThickness(brush:IBrush, x:Number, y:Number, width:Number, height:Number, thickness:Number):void
Fill a ellipse ring with specified thickness.
Graphics2D
  
fillPolygon(brush:IBrush, points:Array):void
Fills a polygon.(close figure automaticlly)
Start with the points[0] and end of the points[0] as a closed path.
Graphics2D
  
fillPolygonRing(brush:IBrush, points1:Array, points2:Array):void
Fills a polygon ring.
Graphics2D
  
fillPolyline(b:IBrush, points:Array):void
Fills a polygon.(not close figure automaticlly)
Start with the points[0] and end with the points[points.length-1] as a closed path.
Graphics2D
  
fillRectangle(brush:IBrush, x:Number, y:Number, width:Number, height:Number):void
Fills a rectange.
Graphics2D
  
fillRectangleRing(brush:IBrush, centerX:Number, centerY:Number, width1:Number, height1:Number, width2:Number, height2:Number):void
Fills a rectange ring.
Graphics2D
  
fillRectangleRingWithThickness(brush:IBrush, x:Number, y:Number, width:Number, height:Number, thickness:Number):void
Fills a rectange ring with a specified thickness.
Graphics2D
  
fillRoundRect(brush:IBrush, x:Number, y:Number, width:Number, height:Number, radius:Number, topRightRadius:Number = -1, bottomLeftRadius:Number = -1, bottomRightRadius:Number = -1):void
Fills a round rectangle.
Graphics2D
  
fillRoundRectRing(brush:IBrush, centerX:Number, centerY:Number, width1:Number, height1:Number, radius1:Number, width2:Number, height2:Number, radius2:Number):void
Fill a round rect ring.
Graphics2D
  
fillRoundRectRingWithThickness(brush:IBrush, x:Number, y:Number, width:Number, height:Number, radius:Number, thickness:Number, innerRadius:Number = -1):void
Fill a round rect ring with specified thickness.
Graphics2D
  
line(x1:Number, y1:Number, x2:Number, y2:Number):void
Paths a line between the points (x1, y1) and (x2, y2) in the target Graphics.
Graphics2D
  
lineTo(x:Number, y:Number):void
Graphics2D
  
moveTo(x:Number, y:Number):void
Delegate Graphics.moveTo(x,y);
Graphics2D
  
polygon(points:Array):void
Paths a polygon.(close figure automaticlly)
Graphics2D
  
polyline(points:Array):void
Paths a polyline(not close figure automaticlly).
Graphics2D
  
rectangle(x:Number, y:Number, width:Number, height:Number):void
Paths a rectangle.
Graphics2D
  
roundRect(x:Number, y:Number, width:Number, height:Number, radius:Number, topRightRadius:Number = -1, bottomLeftRadius:Number = -1, bottomRightRadius:Number = -1):void
Paths a round rect.
Graphics2D
Protected Methods
 MethodDefined by
  
dispose():void
Graphics2D
  
setTarget(target:Graphics):void
Graphics2D
Property detail
targetproperty
protected var target:Graphics
Constructor detail
Graphics2D()constructor
public function Graphics2D(target:Graphics)

Constructor take instance of flash.display.Graphics as parameter. usually, you can the instance from a displayObject's graphics property

Parameters
target:Graphics — where the graphics contexts will be paint on. the target is an instance of flash.display.Graphics

See also

Method detail
beginDraw()method
public function beginDraw(pen:IPen):void

Start to draw lines with pen

Parameters
pen:IPen
beginFill()method 
public function beginFill(brush:IBrush):void

Start to fill a closed area with brush

Parameters
brush:IBrush
circle()method 
public function circle(centerX:Number, centerY:Number, radius:Number):void

Paths a circle

Parameters
centerX:Number — x corrdinate of the center of the circle.
 
centerY:Number — y corrdinate of the center of the circle.
 
radius:Number — the radius of circle.

See also

clear()method 
public function clear():void

Clears the graphics contexts drawn on the target Graphics.

curveTo()method 
public function curveTo(controlX:Number, controlY:Number, anchorX:Number, anchorY:Number):void

Paths a curve

Parameters
controlX:Number
 
controlY:Number
 
anchorX:Number
 
anchorY:Number

See also

dispose()method 
protected function dispose():void
drawCircle()method 
public function drawCircle(pen:IPen, centerX:Number, centerY:Number, radius:Number):void

Draws a circle.

Parameters
pen:IPen — the pen to draw.
 
centerX:Number — the center of the circle's x corrdinate.
 
centerY:Number — the center of the circle's y corrdinate.
 
radius:Number — the radius of the circle.
drawEllipse()method 
public function drawEllipse(pen:IPen, x:Number, y:Number, width:Number, height:Number):void

Draws a ellipse.

Parameters
pen:IPen — the pen to draw.
 
x:Number — the left top the ellipse bounds' x corrdinate.
 
y:Number — the left top the ellipse bounds' y corrdinate.
 
width:Number — the width of ellipse bounds.
 
height:Number — the height of ellipse bounds.
drawLine()method 
public function drawLine(p:IPen, x1:Number, y1:Number, x2:Number, y2:Number):void

Draw a line between the points (x1, y1) and (x2, y2) in the target Graphics.

Parameters
p:IPen — the pen to draw. Pen can be a normal Pen or a GradientPen
 
x1:Number — the x corrdinate of the first point.
 
y1:Number — the y corrdinate of the first point.
 
x2:Number — the x corrdinate of the sencod point.
 
y2:Number — the y corrdinate of the sencod point.
drawPolygon()method 
public function drawPolygon(pen:Pen, points:Array):void

Draws a polygon.(close figure automaticlly)
Start to draw a ploygon with the points[0] as the start point and go through all the points in the array then go back to the points[0] end it as a closed path.

Parameters
pen:Pen — the pen to draw
 
points:Array — the Array contains all vertex points in the polygon.

See also

drawPolyline()method 
public function drawPolyline(p:IPen, points:Array):void

Draws a polyline. (not close figure automaticlly)
Start with the points[0] and end with the points[points.length-1] as a closed path.

Parameters
p:IPen — the pen to draw
 
points:Array — the Array contains all vertex points in the polygon.

See also

drawRectangle()method 
public function drawRectangle(pen:IPen, x:Number, y:Number, width:Number, height:Number):void

Draws a rectange.

Parameters
pen:IPen — the pen to draw.
 
x:Number — the left top the rectange bounds' x corrdinate.
 
y:Number — the left top the rectange bounds' y corrdinate.
 
width:Number — the width of rectange bounds.
 
height:Number — the height of rectange bounds.
drawRoundRect()method 
public function drawRoundRect(pen:IPen, x:Number, y:Number, width:Number, height:Number, radius:Number, trR:Number = -1, blR:Number = -1, brR:Number = -1):void

Draws a round rectangle.

Parameters
pen:IPen — the pen to draw.
 
x:Number — the left top the rectangle bounds' x corrdinate.
 
y:Number — the left top the rectangle bounds' y corrdinate.
 
width:Number — the width of rectangle bounds.
 
height:Number — the height of rectangle bounds.
 
radius:Number — the top left corner's round radius.
 
trR:Number (default = -1) — (optional)the top right corner's round radius. (miss this param default to same as radius)
 
blR:Number (default = -1) — (optional)the bottom left corner's round radius. (miss this param default to same as radius)
 
brR:Number (default = -1) — (optional)the bottom right corner's round radius. (miss this param default to same as radius)
ellipse()method 
public function ellipse(x:Number, y:Number, width:Number, height:Number):void

Paths an ellipse.

Parameters
x:Number — the x corrdinate of the ellipse.
 
y:Number — the y corrdinate of the ellipse.
 
width:Number — the width corrdinate of ellipse.
 
height:Number — the width corrdinate of ellipse.

See also

endDraw()method 
public function endDraw():void

Stop drawing

endFill()method 
public function endFill():void

Stop filling a closed area with brush

fillCircle()method 
public function fillCircle(brush:IBrush, centerX:Number, centerY:Number, radius:Number):void

Fills a circle.

Parameters
brush:IBrush — the brush to draw.
 
centerX:Number — the center of the circle's x corrdinate.
 
centerY:Number — the center of the circle's y corrdinate.
 
radius:Number — the radius of the circle.
fillCircleRing()method 
public function fillCircleRing(brush:IBrush, centerX:Number, centerY:Number, radius1:Number, radius2:Number):void

Fills a circle ring.

Parameters
brush:IBrush — the brush to draw.
 
centerX:Number — the center of the ring's x corrdinate.
 
centerY:Number — the center of the ring's y corrdinate.
 
radius1:Number — the first circle radius.
 
radius2:Number — the second circle radius.
fillCircleRingWithThickness()method 
public function fillCircleRingWithThickness(brush:IBrush, centerX:Number, centerY:Number, radius:Number, thickness:Number):void

Fills a circle ring with a specified thickness.

Parameters
brush:IBrush — the brush to draw.
 
centerX:Number — the center of the ring's x corrdinate.
 
centerY:Number — the center of the ring's y corrdinate.
 
radius:Number — the radius of circle periphery.
 
thickness:Number — the thickness of the ring.
fillEllipse()method 
public function fillEllipse(brush:IBrush, x:Number, y:Number, width:Number, height:Number):void

Fills a rectange.

Parameters
brush:IBrush — the brush to fill.
 
x:Number — the left top the ellipse bounds' x corrdinate.
 
y:Number — the left top the ellipse bounds' y corrdinate.
 
width:Number — the width of ellipse bounds.
 
height:Number — the height of ellipse bounds.
fillEllipseRing()method 
public function fillEllipseRing(brush:IBrush, centerX:Number, centerY:Number, width1:Number, height1:Number, width2:Number, height2:Number):void

Fill a ellipse ring.

Parameters
brush:IBrush — the brush to fill.
 
centerX:Number — the center of the ring's x corrdinate.
 
centerY:Number — the center of the ring's y corrdinate.
 
width1:Number — the first eclipse's width.
 
height1:Number — the first eclipse's height.
 
width2:Number — the second eclipse's width.
 
height2:Number — the second eclipse's height.
fillEllipseRingWithThickness()method 
public function fillEllipseRingWithThickness(brush:IBrush, x:Number, y:Number, width:Number, height:Number, thickness:Number):void

Fill a ellipse ring with specified thickness.

Parameters
brush:IBrush — the brush to fill.
 
x:Number — the left top the ring bounds' x corrdinate.
 
y:Number — the left top the ring bounds' y corrdinate.
 
width:Number — the width of ellipse periphery bounds.
 
height:Number — the height of ellipse periphery bounds.
 
thickness:Number — the thickness of the ring.
fillPolygon()method 
public function fillPolygon(brush:IBrush, points:Array):void

Fills a polygon.(close figure automaticlly)
Start with the points[0] and end of the points[0] as a closed path.

Parameters
brush:IBrush — the brush to fill.
 
points:Array — the Array contains all vertex points in the polygon.

See also

fillPolygonRing()method 
public function fillPolygonRing(brush:IBrush, points1:Array, points2:Array):void

Fills a polygon ring.

Parameters
brush:IBrush — the brush to fill.
 
points1:Array — the first polygon's points.
 
points2:Array — the second polygon's points.

See also

fillPolyline()method 
public function fillPolyline(b:IBrush, points:Array):void

Fills a polygon.(not close figure automaticlly)
Start with the points[0] and end with the points[points.length-1] as a closed path.

Parameters
b:IBrush — the brush to fill.
 
points:Array — the Array contains all vertex points in the polygon.

See also

fillRectangle()method 
public function fillRectangle(brush:IBrush, x:Number, y:Number, width:Number, height:Number):void

Fills a rectange.

Parameters
brush:IBrush — the brush to fill.
 
x:Number — the left top the rectange bounds' x corrdinate.
 
y:Number — the left top the rectange bounds' y corrdinate.
 
width:Number — the width of rectange bounds.
 
height:Number — the height of rectange bounds.
fillRectangleRing()method 
public function fillRectangleRing(brush:IBrush, centerX:Number, centerY:Number, width1:Number, height1:Number, width2:Number, height2:Number):void

Fills a rectange ring.

Parameters
brush:IBrush — the brush to fill.
 
centerX:Number — the center of the ring's x corrdinate.
 
centerY:Number — the center of the ring's y corrdinate.
 
width1:Number — the first rectange's width.
 
height1:Number — the first rectange's height.
 
width2:Number — the second rectange's width.
 
height2:Number — the second rectange's height.
fillRectangleRingWithThickness()method 
public function fillRectangleRingWithThickness(brush:IBrush, x:Number, y:Number, width:Number, height:Number, thickness:Number):void

Fills a rectange ring with a specified thickness.

Parameters
brush:IBrush — the brush to fill.
 
x:Number — the left top the ring bounds' x corrdinate.
 
y:Number — the left top the ring bounds' y corrdinate.
 
width:Number — the width of ring periphery bounds.
 
height:Number — the height of ring periphery bounds.
 
thickness:Number — the thickness of the ring.
fillRoundRect()method 
public function fillRoundRect(brush:IBrush, x:Number, y:Number, width:Number, height:Number, radius:Number, topRightRadius:Number = -1, bottomLeftRadius:Number = -1, bottomRightRadius:Number = -1):void

Fills a round rectangle.

Parameters
brush:IBrush — the brush to fill.
 
x:Number — the left top the rectangle bounds' x corrdinate.
 
y:Number — the left top the rectangle bounds' y corrdinate.
 
width:Number — the width of rectangle bounds.
 
height:Number — the height of rectangle bounds.
 
radius:Number — the radius of the top left corner, if other corner radius is -1, will use this radius as default
 
topRightRadius:Number (default = -1) — the radius of the top right corner, if omitted, use the top left as default.
 
bottomLeftRadius:Number (default = -1) — the radius of the bottom left corner, if omitted, use the top left as default.
 
bottomRightRadius:Number (default = -1) — the radius of the bottom right corner, if omitted, use the top left as default.
fillRoundRectRing()method 
public function fillRoundRectRing(brush:IBrush, centerX:Number, centerY:Number, width1:Number, height1:Number, radius1:Number, width2:Number, height2:Number, radius2:Number):void

Fill a round rect ring.

Parameters
brush:IBrush — the brush to fill
 
centerX:Number — the center of the ring's x corrdinate
 
centerY:Number — the center of the ring's y corrdinate
 
width1:Number — the first round rect's width
 
height1:Number — the first round rect's height
 
radius1:Number — the first round rect's round radius
 
width2:Number — the second round rect's width
 
height2:Number — the second round rect's height
 
radius2:Number — the second round rect's round radius
fillRoundRectRingWithThickness()method 
public function fillRoundRectRingWithThickness(brush:IBrush, x:Number, y:Number, width:Number, height:Number, radius:Number, thickness:Number, innerRadius:Number = -1):void

Fill a round rect ring with specified thickness.

Parameters
brush:IBrush — the brush to fill
 
x:Number — the left top the ring bounds' x corrdinate
 
y:Number — the left top the ring bounds' y corrdinate
 
width:Number — the width of ring periphery bounds
 
height:Number — the height of ring periphery bounds
 
radius:Number — the round radius of the round rect
 
thickness:Number — the thickness of the ring
 
innerRadius:Number (default = -1) — the inboard round radius, default is r-t
line()method 
public function line(x1:Number, y1:Number, x2:Number, y2:Number):void

Paths a line between the points (x1, y1) and (x2, y2) in the target Graphics.

Parameters
x1:Number — the x corrdinate of the first point.
 
y1:Number — the y corrdinate of the first point.
 
x2:Number — the x corrdinate of the sencod point.
 
y2:Number — the y corrdinate of the sencod point.
lineTo()method 
public function lineTo(x:Number, y:Number):voidParameters
x:Number
 
y:Number
moveTo()method 
public function moveTo(x:Number, y:Number):void

Delegate Graphics.moveTo(x,y);

Parameters
x:Number
 
y:Number
polygon()method 
public function polygon(points:Array):void

Paths a polygon.(close figure automaticlly)

Parameters
points:Array — the points of the polygon, the array length should be larger than 1

See also

polyline()method 
public function polyline(points:Array):void

Paths a polyline(not close figure automaticlly).

Parameters
points:Array — the points of the polygon, the array length should be larger than 1

See also

rectangle()method 
public function rectangle(x:Number, y:Number, width:Number, height:Number):void

Paths a rectangle.

Parameters
x:Number — the x corrdinate of the rectangle.
 
y:Number — the y corrdinate of the rectangle.
 
width:Number — the width corrdinate of rectangle.
 
height:Number — the width corrdinate of rectangle.

See also

roundRect()method 
public function roundRect(x:Number, y:Number, width:Number, height:Number, radius:Number, topRightRadius:Number = -1, bottomLeftRadius:Number = -1, bottomRightRadius:Number = -1):void

Paths a round rect.

Parameters
x:Number — the x corrdinate of the roundRect.
 
y:Number — the y corrdinate of the roundRect.
 
width:Number — the width corrdinate of roundRect.
 
height:Number — the width corrdinate of roundRect.
 
radius:Number — the radius of the top left corner, if other corner radius is -1, will use this radius as default
 
topRightRadius:Number (default = -1) — (optional)the radius of the top right corner, if omitted, use the top left as default.
 
bottomLeftRadius:Number (default = -1) — (optional)the radius of the bottom left corner, if omitted, use the top left as default.
 
bottomRightRadius:Number (default = -1) — (optional)the radius of the bottom right corner, if omitted, use the top left as default.

See also

setTarget()method 
protected function setTarget(target:Graphics):voidParameters
target:Graphics