class flash.display.Graphics
Available on all platforms
The Graphics class contains a set of methods that you can use to create a
* vector shape. Display objects that support drawing include Sprite and Shape
* objects. Each of these classes includes a You cannot create a Graphics object directly from ActionScript code. If
* you call graphics
property
* that is a Graphics object. The following are among those helper functions
* provided for ease of use: drawRect()
,
* drawRoundRect()
, drawCircle()
, and
* drawEllipse()
.
* new Graphics()
, an exception is thrown.
The Graphics class is final; it cannot be subclassed.
Instance Fields
function beginBitmapFill(bitmap:BitmapData, ?matrix:Matrix, ?repeat:Bool, ?smooth:Bool):Void
Fills a drawing area with a bitmap image. The bitmap can be repeated or
* tiled to fill the area. The fill remains in effect until you call the
* beginFill()
, beginBitmapFill()
,
* beginGradientFill()
, or beginShaderFill()
* method. Calling the clear()
method clears the fill.
*
*
The application renders the fill whenever three or more points are
* drawn, or when the endFill()
method is called.
bitmap | A transparent or opaque bitmap image that contains the bits to be displayed. |
matrix | A matrix object(of the flash.geom.Matrix class), which you can use to define transformations on the bitmap. For example, you can use the following matrix to rotate a bitmap by 45 degrees(pi/4 radians): |
repeat | If For example, consider the following bitmap(a 20 x
When When |
smooth | If |
function beginFill(color:UInt, ?alpha:Float):Void
Specifies a simple one-color fill that subsequent calls to other Graphics
* methods(such as lineTo()
or drawCircle()
) use
* when drawing. The fill remains in effect until you call the
* beginFill()
, beginBitmapFill()
,
* beginGradientFill()
, or beginShaderFill()
* method. Calling the clear()
method clears the fill.
*
*
The application renders the fill whenever three or more points are
* drawn, or when the endFill()
method is called.
color | The color of the fill(0xRRGGBB). * |
alpha | The alpha value of the fill(0.0 to 1.0). |
function beginGradientFill(type:GradientType, colors:Array<UInt>, alphas:Array<Dynamic>, ratios:Array<Dynamic>, ?matrix:Matrix, ?spreadMethod:SpreadMethod, ?interpolationMethod:InterpolationMethod, ?focalPointRatio:Float):Void
Specifies a gradient fill used by subsequent calls to other Graphics
* methods(such as lineTo()
or drawCircle()
) for
* the object. The fill remains in effect until you call the
* beginFill()
, beginBitmapFill()
,
* beginGradientFill()
, or beginShaderFill()
* method. Calling the clear()
method clears the fill.
*
*
The application renders the fill whenever three or more points are
* drawn, or when the endFill()
method is called.
type | A value from the GradientType class that
* specifies which gradient type to use:
* |
matrix | A transformation matrix as defined by the
* flash.geom.Matrix class. The flash.geom.Matrix
* class includes a
* |
spreadMethod | A value from the SpreadMethod class that
* specifies which spread method to use, either:
* For example, consider a simple linear
* gradient between two colors: This example uses
* If you use If you use |
interpolationMethod | A value from the InterpolationMethod class that
specifies which value to use:
For example, consider a simple linear
|
focalPointRatio | A number that controls the location of the
* focal point of the gradient. 0 means that the
* focal point is in the center. 1 means that the
* focal point is at one border of the gradient
* circle. -1 means that the focal point is at the
* other border of the gradient circle. A value
* less than -1 or greater than 1 is rounded to -1
* or 1. For example, the following example shows
* a |
function beginShaderFill(shader:Shader, ?matrix:Matrix):Void
Specifies a shader fill used by subsequent calls to other Graphics methods
* (such as The application renders the fill whenever three or more points are
* drawn, or when the lineTo()
or drawCircle()
) for the
* object. The fill remains in effect until you call the
* beginFill()
, beginBitmapFill()
,
* beginGradientFill()
, or beginShaderFill()
* method. Calling the clear()
method clears the fill.
* endFill()
method is called.
Shader fills are not supported under GPU rendering; filled areas will * be colored cyan.
* *shader | The shader to use for the fill. This Shader instance is not
required to specify an image input. However, if an image
input is specified in the shader, the input must be provided
manually. To specify the input, set the When you pass a Shader instance as an argument the shader
|
matrix | A matrix object(of the flash.geom.Matrix class), which you
can use to define transformations on the shader. For
example, you can use the following matrix to rotate a shader
by 45 degrees(pi/4 radians):
The coordinates received in the shader are based on the
|
Clears the graphics that were drawn to this Graphics object, and resets * fill and line style settings.
function copyFrom(sourceGraphics:Graphics):Void
Copies all of drawing commands from the source Graphics object into the * calling Graphics object. * *
sourceGraphics | The Graphics object from which to copy the drawing * commands. |
function cubicCurveTo(controlX1:Float, controlY1:Float, controlX2:Float, controlY2:Float, anchorX:Float, anchorY:Float):Void
function curveTo(controlX:Float, controlY:Float, anchorX:Float, anchorY:Float):Void
Draws a curve using the current line style from the current drawing
* position to(anchorX, anchorY) and using the control point that
* (controlX
, controlY
) specifies. The current
* drawing position is then set to(anchorX
,
* anchorY
). If the movie clip in which you are drawing contains
* content created with the Flash drawing tools, calls to the
* curveTo()
method are drawn underneath this content. If you
* call the curveTo()
method before any calls to the
* moveTo()
method, the default of the current drawing position
* is(0, 0). If any of the parameters are missing, this method fails and the
* current drawing position is not changed.
*
*
The curve drawn is a quadratic Bezier curve. Quadratic Bezier curves * consist of two anchor points and one control point. The curve interpolates * the two anchor points and curves toward the control point.
* *controlX | A number that specifies the horizontal position of the control point relative to the registration point of the parent display object. * |
controlY | A number that specifies the vertical position of the control point relative to the registration point of the parent display object. * |
anchorX | A number that specifies the horizontal position of the * next anchor point relative to the registration point of * the parent display object. * |
anchorY | A number that specifies the vertical position of the next * anchor point relative to the registration point of the * parent display object. |
function drawCircle(x:Float, y:Float, radius:Float):Void
Draws a circle. Set the line style, fill, or both before you call the
* drawCircle()
method, by calling the linestyle()
,
* lineGradientStyle()
, beginFill()
,
* beginGradientFill()
, or beginBitmapFill()
* method.
*
*
x | The x location of the center of the circle relative * to the registration point of the parent display object(in * pixels). * |
y | The y location of the center of the circle relative * to the registration point of the parent display object(in * pixels). * |
radius | The radius of the circle(in pixels). |
function drawEllipse(x:Float, y:Float, width:Float, height:Float):Void
Draws an ellipse. Set the line style, fill, or both before you call the
* drawEllipse()
method, by calling the
* linestyle()
, lineGradientStyle()
,
* beginFill()
, beginGradientFill()
, or
* beginBitmapFill()
method.
*
*
x | The x location of the top-left of the bounding-box of * the ellipse relative to the registration point of the parent * display object(in pixels). * |
y | The y location of the top left of the bounding-box of * the ellipse relative to the registration point of the parent * display object(in pixels). * |
width | The width of the ellipse(in pixels). * |
height | The height of the ellipse(in pixels). |
function drawGraphicsData(graphicsData:Vector<IGraphicsData>):Void
Submits a series of IGraphicsData instances for drawing. This method * accepts a Vector containing objects including paths, fills, and strokes * that implement the IGraphicsData interface. A Vector of IGraphicsData * instances can refer to a part of a shape, or a complex fully defined set * of data for rendering a complete shape. * *
Graphics paths can contain other graphics paths. If the
* graphicsData
Vector includes a path, that path and all its
* sub-paths are rendered during this operation.
function drawPath(commands:Vector<Int>, data:Vector<Float>, ?winding:GraphicsPathWinding):Void
Submits a series of commands for drawing. The Generally, drawings render faster with drawPath()
* method uses vector arrays to consolidate individual moveTo()
,
* lineTo()
, and curveTo()
drawing commands into a
* single call. The drawPath()
method parameters combine drawing
* commands with x- and y-coordinate value pairs and a drawing direction. The
* drawing commands are values from the GraphicsPathCommand class. The x- and
* y-coordinate value pairs are Numbers in an array where each pair defines a
* coordinate location. The drawing direction is a value from the
* GraphicsPathWinding class.
* drawPath()
than
* with a series of individual lineTo()
and
* curveTo()
methods.
The drawPath()
method uses a uses a floating computation
* so rotation and scaling of shapes is more accurate and gives better
* results. However, curves submitted using the drawPath()
* method can have small sub-pixel alignment errors when used in conjunction
* with the lineTo()
and curveTo()
methods.
The drawPath()
method also uses slightly different rules
* for filling and drawing lines. They are:
-
*
- When a fill is applied to rendering a path:
*
-
*
- A sub-path of less than 3 points is not rendered.(But note that the * stroke rendering will still occur, consistent with the rules for strokes * below.) *
- A sub-path that isn't closed(the end point is not equal to the * begin point) is implicitly closed. *
* - When a stroke is applied to rendering a path:
*
-
*
- The sub-paths can be composed of any number of points. *
- The sub-path is never implicitly closed. *
*
winding | Specifies the winding rule using a value defined in the * GraphicsPathWinding class. |
function drawRect(x:Float, y:Float, width:Float, height:Float):Void
Draws a rectangle. Set the line style, fill, or both before you call the
* drawRect()
method, by calling the linestyle()
,
* lineGradientStyle()
, beginFill()
,
* beginGradientFill()
, or beginBitmapFill()
* method.
*
*
x | A number indicating the horizontal position relative to the * registration point of the parent display object(in pixels). * |
y | A number indicating the vertical position relative to the * registration point of the parent display object(in pixels). * |
width | The width of the rectangle(in pixels). * |
height | The height of the rectangle(in pixels). * |
function drawRoundRect(x:Float, y:Float, width:Float, height:Float, ellipseWidth:Float, ?ellipseHeight:Float):Void
Draws a rounded rectangle. Set the line style, fill, or both before you
* call the drawRoundRect()
method, by calling the
* linestyle()
, lineGradientStyle()
,
* beginFill()
, beginGradientFill()
, or
* beginBitmapFill()
method.
*
*
x | A number indicating the horizontal position relative * to the registration point of the parent display * object(in pixels). * |
y | A number indicating the vertical position relative to * the registration point of the parent display object * (in pixels). * |
width | The width of the round rectangle(in pixels). * |
height | The height of the round rectangle(in pixels). * |
ellipseWidth | The width of the ellipse used to draw the rounded * corners(in pixels). * |
ellipseHeight | The height of the ellipse used to draw the rounded
corners(in pixels). Optional; if no value is
specified, the default value matches that provided
for the |
function drawRoundRectComplex(x:Float, y:Float, width:Float, height:Float, topLeftRadius:Float, topRightRadius:Float, bottomLeftRadius:Float, bottomRightRadius:Float):Void
function drawTriangles(vertices:Vector<Float>, ?indices:Vector<Int>, ?uvtData:Vector<Float>, ?culling:TriangleCulling):Void
Renders a set of triangles, typically to distort bitmaps and give them a
* three-dimensional appearance. The Any type of fill can be used, but if the fill has a transform matrix
* that transform matrix is ignored. drawTriangles()
method maps
* either the current fill, or a bitmap fill, to the triangle faces using a
* set of(u,v) coordinates.
*
A uvtData
parameter improves texture mapping when a
* bitmap fill is used.
culling | Specifies whether to render triangles that face in a specified direction. This parameter prevents the rendering of triangles that cannot be seen in the current view. This parameter can be set to any value defined by the TriangleCulling class. |
Applies a fill to the lines and curves that were added since the last call
* to the beginFill()
, beginGradientFill()
, or
* beginBitmapFill()
method. Flash uses the fill that was
* specified in the previous call to the beginFill()
,
* beginGradientFill()
, or beginBitmapFill()
* method. If the current drawing position does not equal the previous
* position specified in a moveTo()
method and a fill is
* defined, the path is closed with a line and then filled.
function lineBitmapStyle(bitmap:BitmapData, ?matrix:Matrix, ?repeat:Bool, ?smooth:Bool):Void
Specifies a bitmap to use for the line stroke when drawing lines.
* The bitmap line style is used for subsequent calls to Graphics methods
* such as the lineTo()
method or the drawCircle()
* method. The line style remains in effect until you call the
* lineStyle()
or lineGradientStyle()
methods, or
* the lineBitmapStyle()
method again with different parameters.
*
You can call the lineBitmapStyle()
method in the middle of
* drawing a path to specify different styles for different line segments
* within a path.
Call the lineStyle()
method before you call the
* lineBitmapStyle()
method to enable a stroke, or else the
* value of the line style is undefined
.
Calls to the clear()
method set the line style back to
* undefined
.
bitmap | The bitmap to use for the line stroke. * |
matrix | An optional transformation matrix as defined by the flash.geom.Matrix class. The matrix can be used to scale or otherwise manipulate the bitmap before applying it to the line style. |
repeat | Whether to repeat the bitmap in a tiled fashion. * |
smooth | Whether smoothing should be applied to the bitmap. |
function lineGradientStyle(type:GradientType, colors:Array<UInt>, alphas:Array<Dynamic>, ratios:Array<Dynamic>, ?matrix:Matrix, ?spreadMethod:SpreadMethod, ?interpolationMethod:InterpolationMethod, ?focalPointRatio:Float):Void
Specifies a gradient to use for the stroke when drawing lines.
* The gradient line style is used for subsequent calls to Graphics
* methods such as the lineTo()
methods or the
* drawCircle()
method. The line style remains in effect until
* you call the lineStyle()
or lineBitmapStyle()
* methods, or the lineGradientStyle()
method again with
* different parameters.
You can call the lineGradientStyle()
method in the middle
* of drawing a path to specify different styles for different line segments
* within a path.
Call the lineStyle()
method before you call the
* lineGradientStyle()
method to enable a stroke, or else the
* value of the line style is undefined
.
Calls to the clear()
method set the line style back to
* undefined
.
type | A value from the GradientType class that * specifies which gradient type to use, either * GradientType.LINEAR or GradientType.RADIAL. * |
matrix | A transformation matrix as defined by the
* flash.geom.Matrix class. The flash.geom.Matrix
* class includes a
* |
spreadMethod | A value from the SpreadMethod class that * specifies which spread method to use: * |
interpolationMethod | A value from the InterpolationMethod class that
specifies which value to use. For example,
consider a simple linear gradient between two
colors(with the |
focalPointRatio | A number that controls the location of the
* focal point of the gradient. The value 0 means
* the focal point is in the center. The value 1
* means the focal point is at one border of the
* gradient circle. The value -1 means that the
* focal point is at the other border of the
* gradient circle. Values less than -1 or greater
* than 1 are rounded to -1 or 1. The following
* image shows a gradient with a
* |
function lineShaderStyle(shader:Shader, ?matrix:Matrix):Void
Specifies a shader to use for the line stroke when drawing lines.
* The shader line style is used for subsequent calls to Graphics methods
* such as the lineTo()
method or the drawCircle()
* method. The line style remains in effect until you call the
* lineStyle()
or lineGradientStyle()
methods, or
* the lineBitmapStyle()
method again with different parameters.
*
You can call the lineShaderStyle()
method in the middle of
* drawing a path to specify different styles for different line segments
* within a path.
Call the lineStyle()
method before you call the
* lineShaderStyle()
method to enable a stroke, or else the
* value of the line style is undefined
.
Calls to the clear()
method set the line style back to
* undefined
.
shader | The shader to use for the line stroke. * |
matrix | An optional transformation matrix as defined by the flash.geom.Matrix class. The matrix can be used to scale or otherwise manipulate the bitmap before applying it to the * line style. |
function lineStyle(?thickness:Float, ?color:UInt, ?alpha:Float, ?pixelHinting:Bool, ?scaleMode:LineScaleMode, ?caps:CapsStyle, ?joints:JointStyle, ?miterLimit:Float):Void
Specifies a line style used for subsequent calls to Graphics methods such
* as the You can call the lineTo()
method or the drawCircle()
* method. The line style remains in effect until you call the
* lineGradientStyle()
method, the
* lineBitmapStyle()
method, or the lineStyle()
* method with different parameters.
* lineStyle()
method in the middle of
* drawing a path to specify different styles for different line segments
* within the path.
Note: Calls to the clear()
method set the line
* style back to undefined
.
Note: Flash Lite 4 supports only the first three parameters
* (thickness
, color
, and alpha
).
thickness | An integer that indicates the thickness of the line in * points; valid values are 0-255. If a number is not * specified, or if the parameter is undefined, a line is * not drawn. If a value of less than 0 is passed, the * default is 0. The value 0 indicates hairline * thickness; the maximum thickness is 255. If a value * greater than 255 is passed, the default is 255. * |
color | A hexadecimal color value of the line; for example, * red is 0xFF0000, blue is 0x0000FF, and so on. If a * value is not indicated, the default is 0x000000 * (black). Optional. * |
alpha | A number that indicates the alpha value of the color * of the line; valid values are 0 to 1. If a value is * not indicated, the default is 1(solid). If the value * is less than 0, the default is 0. If the value is * greater than 1, the default is 1. * |
pixelHinting(Not | supported in Flash Lite 4) A Boolean value that
specifies whether to hint strokes to full pixels. This
affects both the position of anchors of a curve and
the line stroke size itself. With
If a value is not supplied, the line does not use pixel hinting. |
scaleMode | (Not supported in Flash Lite 4) A value from the * LineScaleMode class that specifies which scale mode to * use: *
|
caps | (Not supported in Flash Lite 4) A value from the
* CapsStyle class that specifies the type of caps at the
* end of lines. Valid values are:
* For example, the following illustrations show the
* different |
joints | (Not supported in Flash Lite 4) A value from the
* JointStyle class that specifies the type of joint
* appearance used at angles. Valid values are:
* For example, the following illustrations show the
* different Note: For |
miterLimit | (Not supported in Flash Lite 4) A number that
* indicates the limit at which a miter is cut off. Valid
* values range from 1 to 255(and values outside that
* range are rounded to 1 or 255). This value is only
* used if the For example, consider the following angled lines,
* each drawn with a Notice that a given |
function lineTo(x:Float, y:Float):Void
Draws a line using the current line style from the current drawing
* position to(x
, y
); the current drawing position
* is then set to(x
, y
). If the display object in
* which you are drawing contains content that was created with the Flash
* drawing tools, calls to the lineTo()
method are drawn
* underneath the content. If you call lineTo()
before any calls
* to the moveTo()
method, the default position for the current
* drawing is(0, 0). If any of the parameters are missing, this
* method fails and the current drawing position is not changed.
*
*
x | A number that indicates the horizontal position relative to the registration point of the parent display object(in pixels). |
y | A number that indicates the vertical position relative to the * registration point of the parent display object(in pixels). |
function moveTo(x:Float, y:Float):Void
Moves the current drawing position to(x
, y
). If
* any of the parameters are missing, this method fails and the current
* drawing position is not changed.
*
*
x | A number that indicates the horizontal position relative to the registration point of the parent display object(in pixels). |
y | A number that indicates the vertical position relative to the * registration point of the parent display object(in pixels). |