用于 Adobe® Flash® Platform 的 ActionScript® 3.0 参考
主页  |  隐藏包列表和类列表 |   |   |  新增内容  |  索引  |  附录  |  为什么显示为英语?
过滤条件: AIR 30.0 和更早版本, Flash Player 30.0 和更早版本, Flash Lite 4
Flex 4.6 和更早版本, Flash Pro CS6 和更早版本
隐藏过滤条件
flash.display 

Graphics  - AS3

x

顶级
adobe.utils
air.desktop
air.net
air.update
air.update.events
coldfusion.air
coldfusion.air.errors
coldfusion.air.events
coldfusion.service
coldfusion.service.events
coldfusion.service.mxml
com.adobe.acm.solutions.authoring.domain.extensions
com.adobe.acm.solutions.ccr.domain.extensions
com.adobe.consulting.pst.vo
com.adobe.dct.component
com.adobe.dct.component.datadictionary
com.adobe.dct.component.datadictionaryElement
com.adobe.dct.component.dataElementsPanel
com.adobe.dct.component.toolbars
com.adobe.dct.event
com.adobe.dct.exp
com.adobe.dct.model
com.adobe.dct.service
com.adobe.dct.service.provider
com.adobe.dct.transfer
com.adobe.dct.util
com.adobe.dct.view
com.adobe.ep.taskmanagement.domain
com.adobe.ep.taskmanagement.event
com.adobe.ep.taskmanagement.filter
com.adobe.ep.taskmanagement.services
com.adobe.ep.taskmanagement.util
com.adobe.ep.ux.attachmentlist.component
com.adobe.ep.ux.attachmentlist.domain
com.adobe.ep.ux.attachmentlist.domain.events
com.adobe.ep.ux.attachmentlist.domain.renderers
com.adobe.ep.ux.attachmentlist.skin
com.adobe.ep.ux.attachmentlist.skin.renderers
com.adobe.ep.ux.content.event
com.adobe.ep.ux.content.factory
com.adobe.ep.ux.content.handlers
com.adobe.ep.ux.content.managers
com.adobe.ep.ux.content.model.asset
com.adobe.ep.ux.content.model.preview
com.adobe.ep.ux.content.model.relation
com.adobe.ep.ux.content.model.search
com.adobe.ep.ux.content.model.toolbar
com.adobe.ep.ux.content.search
com.adobe.ep.ux.content.services
com.adobe.ep.ux.content.services.load
com.adobe.ep.ux.content.services.permissions
com.adobe.ep.ux.content.services.preview
com.adobe.ep.ux.content.services.providers
com.adobe.ep.ux.content.services.query
com.adobe.ep.ux.content.services.relationships
com.adobe.ep.ux.content.services.search.lccontent
com.adobe.ep.ux.content.services.version
com.adobe.ep.ux.content.view
com.adobe.ep.ux.content.view.components.activate
com.adobe.ep.ux.content.view.components.grid
com.adobe.ep.ux.content.view.components.grid.hover
com.adobe.ep.ux.content.view.components.grid.hover.component
com.adobe.ep.ux.content.view.components.grid.renderers
com.adobe.ep.ux.content.view.components.relationships
com.adobe.ep.ux.content.view.components.review
com.adobe.ep.ux.content.view.components.search.renderers
com.adobe.ep.ux.content.view.components.searchpod
com.adobe.ep.ux.content.view.components.toolbar
com.adobe.ep.ux.content.view.components.toolbar.controlRenderers
com.adobe.ep.ux.content.view.components.version
com.adobe.ep.ux.documentsubmit.component
com.adobe.ep.ux.documentsubmit.domain
com.adobe.ep.ux.documentsubmit.skin
com.adobe.ep.ux.taskaction.component
com.adobe.ep.ux.taskaction.domain
com.adobe.ep.ux.taskaction.domain.events
com.adobe.ep.ux.taskaction.skin
com.adobe.ep.ux.taskdetails.component
com.adobe.ep.ux.taskdetails.domain
com.adobe.ep.ux.taskdetails.skin
com.adobe.ep.ux.tasklist.component
com.adobe.ep.ux.tasklist.domain
com.adobe.ep.ux.tasklist.skin
com.adobe.ep.ux.webdocumentviewer.domain
com.adobe.exm.expression
com.adobe.exm.expression.error
com.adobe.exm.expression.event
com.adobe.exm.expression.impl
com.adobe.fiber.runtime.lib
com.adobe.fiber.services
com.adobe.fiber.services.wrapper
com.adobe.fiber.styles
com.adobe.fiber.util
com.adobe.fiber.valueobjects
com.adobe.gravity.binding
com.adobe.gravity.context
com.adobe.gravity.flex.bundleloader
com.adobe.gravity.flex.progress
com.adobe.gravity.flex.serviceloader
com.adobe.gravity.framework
com.adobe.gravity.init
com.adobe.gravity.service.bundleloader
com.adobe.gravity.service.logging
com.adobe.gravity.service.manifest
com.adobe.gravity.service.progress
com.adobe.gravity.tracker
com.adobe.gravity.ui
com.adobe.gravity.utility
com.adobe.gravity.utility.async
com.adobe.gravity.utility.error
com.adobe.gravity.utility.events
com.adobe.gravity.utility.factory
com.adobe.gravity.utility.flex.async
com.adobe.gravity.utility.logging
com.adobe.gravity.utility.message
com.adobe.gravity.utility.sequence
com.adobe.gravity.utility.url
com.adobe.guides.control
com.adobe.guides.domain
com.adobe.guides.i18n
com.adobe.guides.spark.components.skins
com.adobe.guides.spark.components.skins.mx
com.adobe.guides.spark.headers.components
com.adobe.guides.spark.headers.skins
com.adobe.guides.spark.layouts.components
com.adobe.guides.spark.layouts.skins
com.adobe.guides.spark.navigators.components
com.adobe.guides.spark.navigators.renderers
com.adobe.guides.spark.navigators.skins
com.adobe.guides.spark.util
com.adobe.guides.spark.wrappers.components
com.adobe.guides.spark.wrappers.skins
com.adobe.guides.submit
com.adobe.icc.dc.domain
com.adobe.icc.dc.domain.factory
com.adobe.icc.editors.events
com.adobe.icc.editors.handlers
com.adobe.icc.editors.managers
com.adobe.icc.editors.model
com.adobe.icc.editors.model.config
com.adobe.icc.editors.model.el
com.adobe.icc.editors.model.el.operands
com.adobe.icc.editors.model.el.operators
com.adobe.icc.enum
com.adobe.icc.external.dc
com.adobe.icc.obj
com.adobe.icc.services
com.adobe.icc.services.category
com.adobe.icc.services.config
com.adobe.icc.services.download
com.adobe.icc.services.export
com.adobe.icc.services.external
com.adobe.icc.services.formbridge
com.adobe.icc.services.fragmentlayout
com.adobe.icc.services.layout
com.adobe.icc.services.letter
com.adobe.icc.services.locator
com.adobe.icc.services.module
com.adobe.icc.services.render
com.adobe.icc.services.submit
com.adobe.icc.services.user
com.adobe.icc.token
com.adobe.icc.vo
com.adobe.icc.vo.render
com.adobe.icomm.assetplacement.controller
com.adobe.icomm.assetplacement.controller.utils
com.adobe.icomm.assetplacement.data
com.adobe.icomm.assetplacement.model
com.adobe.livecycle.assetmanager.client
com.adobe.livecycle.assetmanager.client.event
com.adobe.livecycle.assetmanager.client.handler
com.adobe.livecycle.assetmanager.client.managers
com.adobe.livecycle.assetmanager.client.model
com.adobe.livecycle.assetmanager.client.model.cms
com.adobe.livecycle.assetmanager.client.service
com.adobe.livecycle.assetmanager.client.service.search
com.adobe.livecycle.assetmanager.client.service.search.cms
com.adobe.livecycle.assetmanager.client.utils
com.adobe.livecycle.content
com.adobe.livecycle.rca.model
com.adobe.livecycle.rca.model.constant
com.adobe.livecycle.rca.model.document
com.adobe.livecycle.rca.model.participant
com.adobe.livecycle.rca.model.reminder
com.adobe.livecycle.rca.model.stage
com.adobe.livecycle.rca.service
com.adobe.livecycle.rca.service.core
com.adobe.livecycle.rca.service.core.delegate
com.adobe.livecycle.rca.service.process
com.adobe.livecycle.rca.service.process.delegate
com.adobe.livecycle.rca.token
com.adobe.livecycle.ria.security.api
com.adobe.livecycle.ria.security.service
com.adobe.mosaic.layouts
com.adobe.mosaic.layouts.dragAndDrop
com.adobe.mosaic.layouts.interfaces
com.adobe.mosaic.mxml
com.adobe.mosaic.om.constants
com.adobe.mosaic.om.events
com.adobe.mosaic.om.impl
com.adobe.mosaic.om.interfaces
com.adobe.mosaic.skinning
com.adobe.mosaic.sparklib.editors
com.adobe.mosaic.sparklib.optionMenu
com.adobe.mosaic.sparklib.scrollableMenu
com.adobe.mosaic.sparklib.scrollableMenu.skins
com.adobe.mosaic.sparklib.tabLayout
com.adobe.mosaic.sparklib.tabLayout.events
com.adobe.mosaic.sparklib.tabLayout.layouts
com.adobe.mosaic.sparklib.tabLayout.skins
com.adobe.mosaic.sparklib.text
com.adobe.mosaic.sparklib.util
com.adobe.solutions.acm.authoring.presentation
com.adobe.solutions.acm.authoring.presentation.actionbar
com.adobe.solutions.acm.authoring.presentation.common
com.adobe.solutions.acm.authoring.presentation.events
com.adobe.solutions.acm.authoring.presentation.fragment
com.adobe.solutions.acm.authoring.presentation.letter
com.adobe.solutions.acm.authoring.presentation.letter.data
com.adobe.solutions.acm.authoring.presentation.preview
com.adobe.solutions.acm.authoring.presentation.rte
com.adobe.solutions.acm.ccr.presentation
com.adobe.solutions.acm.ccr.presentation.contentcapture
com.adobe.solutions.acm.ccr.presentation.contentcapture.events
com.adobe.solutions.acm.ccr.presentation.contentcapture.preview
com.adobe.solutions.acm.ccr.presentation.datacapture
com.adobe.solutions.acm.ccr.presentation.datacapture.renderers
com.adobe.solutions.acm.ccr.presentation.pdf
com.adobe.solutions.exm
com.adobe.solutions.exm.authoring
com.adobe.solutions.exm.authoring.components.controls
com.adobe.solutions.exm.authoring.components.toolbars
com.adobe.solutions.exm.authoring.domain
com.adobe.solutions.exm.authoring.domain.expression
com.adobe.solutions.exm.authoring.domain.impl
com.adobe.solutions.exm.authoring.domain.method
com.adobe.solutions.exm.authoring.domain.variable
com.adobe.solutions.exm.authoring.enum
com.adobe.solutions.exm.authoring.events
com.adobe.solutions.exm.authoring.model
com.adobe.solutions.exm.authoring.renderer
com.adobe.solutions.exm.authoring.view
com.adobe.solutions.exm.expression
com.adobe.solutions.exm.impl
com.adobe.solutions.exm.impl.method
com.adobe.solutions.exm.method
com.adobe.solutions.exm.mock
com.adobe.solutions.exm.mock.method
com.adobe.solutions.exm.runtime
com.adobe.solutions.exm.runtime.impl
com.adobe.solutions.exm.variable
com.adobe.solutions.prm.constant
com.adobe.solutions.prm.domain
com.adobe.solutions.prm.domain.factory
com.adobe.solutions.prm.domain.impl
com.adobe.solutions.prm.domain.manager
com.adobe.solutions.prm.presentation.asset
com.adobe.solutions.prm.presentation.constant
com.adobe.solutions.prm.presentation.document
com.adobe.solutions.prm.presentation.event
com.adobe.solutions.prm.presentation.file
com.adobe.solutions.prm.presentation.project
com.adobe.solutions.prm.presentation.team
com.adobe.solutions.prm.presentation.util
com.adobe.solutions.prm.service
com.adobe.solutions.prm.services.impl
com.adobe.solutions.prm.vo
com.adobe.solutions.rca.constant
com.adobe.solutions.rca.domain
com.adobe.solutions.rca.domain.common
com.adobe.solutions.rca.domain.factory
com.adobe.solutions.rca.domain.impl
com.adobe.solutions.rca.domain.impl.manager
com.adobe.solutions.rca.domain.manager
com.adobe.solutions.rca.presentation
com.adobe.solutions.rca.presentation.comment
com.adobe.solutions.rca.presentation.constant
com.adobe.solutions.rca.presentation.event
com.adobe.solutions.rca.presentation.gantt
com.adobe.solutions.rca.presentation.gantt.ruler
com.adobe.solutions.rca.presentation.template
com.adobe.solutions.rca.presentation.template.audit
com.adobe.solutions.rca.presentation.template.definition
com.adobe.solutions.rca.presentation.template.documents
com.adobe.solutions.rca.presentation.template.stages
com.adobe.solutions.rca.presentation.util
com.adobe.solutions.rca.service
com.adobe.solutions.rca.services.impl
com.adobe.solutions.rca.vo
com.adobe.solutions.rca.vo.um
com.adobe.viewsource
fl.accessibility
fl.containers
fl.controls
fl.controls.dataGridClasses
fl.controls.listClasses
fl.controls.progressBarClasses
fl.core
fl.data
fl.display
fl.events
fl.ik
fl.lang
fl.livepreview
fl.managers
fl.motion
fl.motion.easing
fl.rsl
fl.text
fl.transitions
fl.transitions.easing
fl.video
flash.accessibility
flash.concurrent
flash.crypto
flash.data
flash.desktop
flash.display
flash.display3D
flash.display3D.textures
flash.errors
flash.events
flash.external
flash.filesystem
flash.filters
flash.geom
flash.globalization
flash.html
flash.media
flash.net
flash.net.dns
flash.net.drm
flash.notifications
flash.permissions
flash.printing
flash.profiler
flash.sampler
flash.security
flash.sensors
flash.system
flash.text
flash.text.engine
flash.text.ime
flash.ui
flash.utils
flash.xml
flashx.textLayout
flashx.textLayout.compose
flashx.textLayout.container
flashx.textLayout.conversion
flashx.textLayout.edit
flashx.textLayout.elements
flashx.textLayout.events
flashx.textLayout.factory
flashx.textLayout.formats
flashx.textLayout.operations
flashx.textLayout.utils
flashx.undo
ga.controls
ga.layouts
ga.model
ga.uiComponents
ga.util
ga.views
ga.wrappers
lc.foundation
lc.foundation.domain
lc.foundation.events
lc.foundation.ui
lc.foundation.util
lc.preloader
lc.procmgmt
lc.procmgmt.commands
lc.procmgmt.domain
lc.procmgmt.events
lc.procmgmt.formbridge
lc.procmgmt.impl
lc.procmgmt.ui.attachments
lc.procmgmt.ui.controls
lc.procmgmt.ui.controls.card
lc.procmgmt.ui.controls.renderer
lc.procmgmt.ui.help
lc.procmgmt.ui.layout
lc.procmgmt.ui.presentationmodel
lc.procmgmt.ui.process
lc.procmgmt.ui.search
lc.procmgmt.ui.startpoint
lc.procmgmt.ui.task
lc.procmgmt.ui.task.form
lc.procmgmt.ui.task.form.commands
lc.procmgmt.ui.tracking
mx.accessibility
mx.automation
mx.automation.air
mx.automation.delegates
mx.automation.delegates.advancedDataGrid
mx.automation.delegates.charts
mx.automation.delegates.containers
mx.automation.delegates.controls
mx.automation.delegates.controls.dataGridClasses
mx.automation.delegates.controls.fileSystemClasses
mx.automation.delegates.core
mx.automation.delegates.flashflexkit
mx.automation.events
mx.binding
mx.binding.utils
mx.charts
mx.charts.chartClasses
mx.charts.effects
mx.charts.effects.effectClasses
mx.charts.events
mx.charts.renderers
mx.charts.series
mx.charts.series.items
mx.charts.series.renderData
mx.charts.styles
mx.collections
mx.collections.errors
mx.containers
mx.containers.accordionClasses
mx.containers.dividedBoxClasses
mx.containers.errors
mx.containers.utilityClasses
mx.controls
mx.controls.advancedDataGridClasses
mx.controls.dataGridClasses
mx.controls.listClasses
mx.controls.menuClasses
mx.controls.olapDataGridClasses
mx.controls.scrollClasses
mx.controls.sliderClasses
mx.controls.textClasses
mx.controls.treeClasses
mx.controls.videoClasses
mx.core
mx.core.windowClasses
mx.data
mx.data.crypto
mx.data.errors
mx.data.events
mx.data.messages
mx.data.mxml
mx.data.offline.errors
mx.data.utils
mx.effects
mx.effects.easing
mx.effects.effectClasses
mx.events
mx.filters
mx.flash
mx.formatters
mx.geom
mx.graphics
mx.graphics.codec
mx.graphics.shaderClasses
mx.logging
mx.logging.errors
mx.logging.targets
mx.managers
mx.messaging
mx.messaging.channels
mx.messaging.config
mx.messaging.errors
mx.messaging.events
mx.messaging.management
mx.messaging.messages
mx.modules
mx.netmon
mx.olap
mx.olap.aggregators
mx.preloaders
mx.printing
mx.resources
mx.rpc
mx.rpc.events
mx.rpc.http
mx.rpc.http.mxml
mx.rpc.livecycle
mx.rpc.mxml
mx.rpc.remoting
mx.rpc.remoting.mxml
mx.rpc.soap
mx.rpc.soap.mxml
mx.rpc.wsdl
mx.rpc.xml
mx.skins
mx.skins.halo
mx.skins.spark
mx.skins.wireframe
mx.skins.wireframe.windowChrome
mx.states
mx.styles
mx.utils
mx.validators
org.osmf.containers
org.osmf.display
org.osmf.elements
org.osmf.events
org.osmf.layout
org.osmf.logging
org.osmf.media
org.osmf.metadata
org.osmf.net
org.osmf.net.dvr
org.osmf.net.httpstreaming
org.osmf.net.metrics
org.osmf.net.qos
org.osmf.net.rtmpstreaming
org.osmf.net.rules
org.osmf.traits
org.osmf.utils
spark.accessibility
spark.automation.delegates
spark.automation.delegates.components
spark.automation.delegates.components.gridClasses
spark.automation.delegates.components.mediaClasses
spark.automation.delegates.components.supportClasses
spark.automation.delegates.skins.spark
spark.automation.events
spark.collections
spark.components
spark.components.calendarClasses
spark.components.gridClasses
spark.components.mediaClasses
spark.components.supportClasses
spark.components.windowClasses
spark.core
spark.effects
spark.effects.animation
spark.effects.easing
spark.effects.interpolation
spark.effects.supportClasses
spark.events
spark.filters
spark.formatters
spark.formatters.supportClasses
spark.globalization
spark.globalization.supportClasses
spark.layouts
spark.layouts.supportClasses
spark.managers
spark.modules
spark.preloaders
spark.primitives
spark.primitives.supportClasses
spark.skins
spark.skins.mobile
spark.skins.mobile.supportClasses
spark.skins.spark
spark.skins.spark.mediaClasses.fullScreen
spark.skins.spark.mediaClasses.normal
spark.skins.spark.windowChrome
spark.skins.wireframe
spark.skins.wireframe.mediaClasses
spark.skins.wireframe.mediaClasses.fullScreen
spark.transitions
spark.utils
spark.validators
spark.validators.supportClasses
xd.core.axm.enterprise.view.components
xd.core.axm.enterprise.view.skins
xd.core.axm.view.components
xd.core.axm.view.components.support

语言元素

全局常量
全局函数
运算符
语句、关键字和指令
特殊类型

附录

新增内容
编译器错误
编译器警告
运行时错误
迁移到 ActionScript 3
支持的字符集
仅适用于 MXML 的标签
Motion XML 元素
Timed Text 标记
不推荐使用的元素的列表
AccessibilityImplementation 常量
如何使用 ActionScript 示例
法律声明
flash.display
public final class Graphics
继承Graphics Inheritance Object

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

Graphics 类包含一组可用来创建矢量形状的方法。支持绘制的显示对象包括 Sprite 和 Shape 对象。这些类中的每一个类都包括 graphics 属性,该属性是一个 Graphics 对象。以下是为便于使用而提供的一些辅助函数:drawRect()drawRoundRect()drawCircle()drawEllipse()

无法通过 ActionScript 代码直接创建 Graphics 对象。如果调用 new Graphics(),则会引发异常。

Graphics 类是最终类;无法从其派生子类。

查看示例



公共属性
 属性由以下参数定义
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
公共方法
 方法由以下参数定义
  
beginBitmapFill(bitmap:BitmapData, matrix:Matrix = null, repeat:Boolean = true, smooth:Boolean = false):void
用位图图像填充绘图区。
Graphics
  
beginFill(color:uint, alpha:Number = 1.0):void
指定一种简单的单一颜色填充,在绘制时该填充将在随后对其他 Graphics 方法(如 lineTo() 或 drawCircle())的调用中使用。
Graphics
  
beginGradientFill(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void
指定一种渐变填充,用于随后调用对象的其他 Graphics 方法(如 lineTo() 或 drawCircle())。
Graphics
  
beginShaderFill(shader:Shader, matrix:Matrix = null):void
为对象指定着色器填充,供随后调用其他 Graphics 方法(如 lineTo() 或 drawCircle())时使用。
Graphics
  
清除绘制到此 Graphics 对象的图形,并重置填充和线条样式设置。
Graphics
  
copyFrom(sourceGraphics:Graphics):void
将源 Graphics 对象中的所有绘图命令复制到执行调用的 Graphics 对象中。
Graphics
  
cubicCurveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number):void
从当前绘图位置到指定的锚点绘制一条三次贝塞尔曲线。
Graphics
  
curveTo(controlX:Number, controlY:Number, anchorX:Number, anchorY:Number):void
使用当前线条样式和由 (controlX, controlY) 指定的控制点绘制一条从当前绘图位置开始到 (anchorX, anchorY) 结束的二次贝塞尔曲线。
Graphics
  
绘制一个圆。
Graphics
  
drawEllipse(x:Number, y:Number, width:Number, height:Number):void
绘制一个椭圆。
Graphics
  
提交一系列 IGraphicsData 实例来进行绘图。
Graphics
  
drawPath(commands:Vector.<int>, data:Vector.<Number>, winding:String = "evenOdd"):void
提交一系列绘制命令。
Graphics
  
drawRect(x:Number, y:Number, width:Number, height:Number):void
绘制一个矩形。
Graphics
  
drawRoundRect(x:Number, y:Number, width:Number, height:Number, ellipseWidth:Number, ellipseHeight:Number = NaN):void
绘制一个圆角矩形。
Graphics
  
drawTriangles(vertices:Vector.<Number>, indices:Vector.<int> = null, uvtData:Vector.<Number> = null, culling:String = "none"):void
呈现一组三角形(通常用于扭曲位图),并为其指定三维外观。
Graphics
  
对从上一次调用 beginFill()、beginGradientFill() 或 beginBitmapFill() 方法之后添加的直线和曲线应用填充。
Graphics
 Inherited
表示对象是否已经定义了指定的属性。
Object
 Inherited
表示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
  
lineBitmapStyle(bitmap:BitmapData, matrix:Matrix = null, repeat:Boolean = true, smooth:Boolean = false):void
指定一个位图,用于绘制线条时的线条笔触。
Graphics
  
lineGradientStyle(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void
指定一种渐变,用于绘制线条时的笔触。
Graphics
  
lineShaderStyle(shader:Shader, matrix:Matrix = null):void
指定一个着色器以用于绘制线条时的线条笔触。
Graphics
  
lineStyle(thickness:Number = NaN, color:uint = 0, alpha:Number = 1.0, pixelHinting:Boolean = false, scaleMode:String = "normal", caps:String = null, joints:String = null, miterLimit:Number = 3):void
指定一种线条样式以用于随后对 lineTo() 或 drawCircle() 等 Graphics 方法的调用。
Graphics
  
使用当前线条样式绘制一条从当前绘图位置开始到 (x, y) 结束的直线;当前绘图位置随后会设置为 (x, y)。
Graphics
  
将当前绘图位置移动到 (x, y)。
Graphics
 Inherited
表示指定的属性是否存在、是否可枚举。
Object
  
查询 Sprite 或 Shape 对象(也可以是其子对象)的矢量图形内容。
Graphics
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
 Inherited
返回指定对象的原始值。
Object
方法详细信息

beginBitmapFill

()方法
public function beginBitmapFill(bitmap:BitmapData, matrix:Matrix = null, repeat:Boolean = true, smooth:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

用位图图像填充绘图区。可以重复或平铺位图以填充该区域。该填充将保持有效,直到您调用 beginFill()beginBitmapFill()beginGradientFill()beginShaderFill() 方法。调用 clear() 方法会清除填充。

只要绘制 3 个或更多个点,或者调用 endFill() 方法时,应用程序就会呈现填充。

参数

bitmap:BitmapData — 包含要显示的位的透明或不透明位图图像。
 
matrix:Matrix (default = null) — 一个 matrix 对象(属于 flash.geom.Matrix 类),您可以使用它在位图上定义转换。例如,可以使用以下矩阵将位图旋转 45 度(pi/4 弧度):
     matrix = new flash.geom.Matrix(); 
     matrix.rotate(Math.PI / 4);
     
 
repeat:Boolean (default = true) — 如果为 true,则位图图像按平铺模式重复。如果为 false,位图图像不会重复,并且位图边缘将用于所有扩展出位图的填充区域。

例如,请考虑下列位图(20 x 20 像素的棋盘图案):

20 x 20 像素棋盘

repeat 设置为 true 时(如下例所示),位图填充将重复位图:

60 x 60 像素棋盘

repeat 设置为 false 时,位图填充将对位图外部的填充区域使用边缘像素:

60 x 60 像素图像,无重复

 
smooth:Boolean (default = false) — 如果为 false,则使用最近邻点算法来呈现放大的位图图像,而且该图像看起来是像素化的。如果为 true,则使用双线性算法来呈示放大的位图图像。使用最近邻点算法呈现较快。

相关 API 元素


示例  ( 如何使用本示例 )

下面的示例使用一个图像 (image1.jpg),它不断旋转并反复填充一个矩形。
  1. 使用 LoaderURLRequest 对象加载此图像文件 (image1.jpg)。此处,该文件位于与 SWF 文件相同的目录中。需要编译 SWF 文件,并将“本地播放安全性”设置为“只访问本地文件”。
  2. 在加载图像后(Event 为 complete),将调用 drawImage() 方法。如果未正确加载图像,ioErrorHandler() 方法将写入跟踪注释。
  3. drawImage() 方法中,将实例化 BitmapData 对象,并将其宽度和高度设置为图像 (image1.jpg) 的宽度和高度。然后,将源图像绘制到 BitmapData 对象中。接下来,在 mySprite Sprite 对象中绘制一个矩形,并使用 BitmapData 对象对其进行填充。通过使用 Matrix 对象,beginBitmapFill() 方法将图像旋转 45 度,然后开始使用图像填充矩形,直至完成时为止。
package {
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.geom.Matrix;

    public class Graphics_beginBitmapFillExample extends Sprite {
 
        private var url:String = "image1.jpg";
        private var loader:Loader = new Loader();

        public function Graphics_beginBitmapFillExample() {

            var request:URLRequest = new URLRequest(url);
            
            loader.load(request);
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, drawImage);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }

        private function drawImage(event:Event):void {

            var mySprite:Sprite = new Sprite();
            var myBitmap:BitmapData = new BitmapData(loader.width, loader.height, false);
  
            myBitmap.draw(loader, new Matrix());
            
            var matrix:Matrix = new Matrix();
            matrix.rotate(Math.PI/4);
            
            mySprite.graphics.beginBitmapFill(myBitmap, matrix, true);
            mySprite.graphics.drawRect(100, 50, 200, 90);
            mySprite.graphics.endFill();
            
            addChild(mySprite);
        }
 
         private function ioErrorHandler(event:IOErrorEvent):void {
            trace("Unable to load image: " + url);
        }
    }   
}

beginFill

()方法 
public function beginFill(color:uint, alpha:Number = 1.0):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

指定一种简单的单一颜色填充,在绘制时该填充将在随后对其他 Graphics 方法(如 lineTo()drawCircle())的调用中使用。该填充将保持有效,直到您调用 beginFill()beginBitmapFill()beginGradientFill()beginShaderFill() 方法。调用 clear() 方法会清除填充。

只要绘制 3 个或更多个点,或者调用 endFill() 方法时,应用程序就会呈现填充。

参数

color:uint — 填充的颜色 (0xRRGGBB)。
 
alpha:Number (default = 1.0) — 填充的 Alpha 值(从 0.0 到 1.0)。

相关 API 元素


示例
如何使用本示例
有关如何使用此方法的说明,请参阅此类末尾的示例

beginGradientFill

()方法 
public function beginGradientFill(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

指定一种渐变填充,用于随后调用对象的其他 Graphics 方法(如 lineTo()drawCircle())。该填充将保持有效,直到您调用 beginFill()beginBitmapFill()beginGradientFill()beginShaderFill() 方法。调用 clear() 方法会清除填充。

只要绘制 3 个或更多个点,或者调用 endFill() 方法时,应用程序就会呈现填充。

参数

type:String — 用于指定要使用哪种渐变类型的 GradientType 类的值:GradientType.LINEARGradientType.RADIAL
 
colors:Array — 渐变中使用的 RGB 十六进制颜色值的数组(例如,红色为 0xFF0000,蓝色为 0x0000FF,等等)。可以至多指定 15 种颜色。对于每种颜色,请在 alphas 和 ratios 参数中指定对应值。
 
alphas:Array — colors 数组中对应颜色的 alpha 值数组;有效值为 0 到 1。如果值小于 0,则默认值为 0。如果值大于 1,则默认值为 1。
 
ratios:Array — 颜色分布比率的数组;有效值为 0 到 255。该值定义 100% 采样的颜色所在位置的宽度百分比。值 0 表示渐变框中的左侧位置,255 表示渐变框中的右侧位置。

注意:此值表示渐变框中的位置,而不是最终渐变的坐标空间,最终渐变可能会比渐变框更宽或更窄。为 colors 参数中的每个值指定一个值。

例如,对于包括蓝和绿两种颜色的线性渐变,下例显示了基于不同 ratios 数组值的渐变中的颜色配比:

ratios渐变
[0, 127]ratios 为 0 和 127 时蓝色到绿色的线性渐变
[0, 255]ratios 为 0 和 255 时蓝色到绿色的线性渐变
[127, 255]ratios 为 127 和 255 时蓝色到绿色的线性渐变

数组中的值必须持续增加;例如,[0, 63, 127, 190, 255]

 
matrix:Matrix (default = null) — 一个由 flash.geom.Matrix 类定义的转换矩阵。flash.geom.Matrix 类包括 createGradientBox() 方法,通过该方法可以方便地设置矩阵,以便与 beginGradientFill() 方法一起使用。
 
spreadMethod:String (default = "pad") — 用于指定要使用哪种 spread 方法的 SpreadMethod 类的值:SpreadMethod.PADSpreadMethod.REFLECTSpreadMethod.REPEAT

例如,请考虑两种颜色之间的简单线性渐变:

     import flash.geom.*
     import flash.display.*
     var fillType:String = GradientType.LINEAR;
     var colors:Array = [0xFF0000, 0x0000FF];
     var alphas:Array = [1, 1];
     var ratios:Array = [0x00, 0xFF];
     var matr:Matrix = new Matrix();
     matr.createGradientBox(20, 20, 0, 0, 0);
     var spreadMethod:String = SpreadMethod.PAD;
     this.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);        
     this.graphics.drawRect(0,0,100,100);
     

此示例将 SpreadMethod.PAD 用于 spread 方法,并且渐变填充看起来将类似于下图:

以 SpreadMethod.PAD 线性渐变

如果将 SpreadMethod.REFLECT 用于 spread 方法,则渐变填充看起来将类似于下图:

以 SpreadMethod.REFLECT 线性渐变

如果将 SpreadMethod.REPEAT 用于 spread 方法,则渐变填充看起来将类似于下图:

以 SpreadMethod.REPEAT 线性渐变

 
interpolationMethod:String (default = "rgb") — 用于指定要使用哪个值的 InterpolationMethod 类的值:InterpolationMethod.LINEAR_RGBInterpolationMethod.RGB

例如,假设有两种颜色之间的简单线性渐变(spreadMethod 参数设置为 SpreadMethod.REFLECT)。不同的插值方法对外观的影响如下所示:

以 InterpolationMethod.LINEAR_RGB 线性渐变 以 InterpolationMethod.RGB 线性渐变
InterpolationMethod.LINEAR_RGBInterpolationMethod.RGB
 
focalPointRatio:Number (default = 0) — 一个控制渐变的焦点位置的数字。0 表示焦点位于中心。1 表示焦点位于渐变圆的一条边界上。-1 表示焦点位于渐变圆的另一条边界上。小于 -1 或大于 1 的值将舍入为 -1 或 1。例如,下例显示 focalPointRatio 设置为 0.75:

focalPointRatio 设置为 0.75 时的放射状渐变


引发
ArgumentError — 如果 type 参数无效。

相关 API 元素

beginShaderFill

()方法 
public function beginShaderFill(shader:Shader, matrix:Matrix = null):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5

为对象指定着色器填充,供随后调用其他 Graphics 方法(如 lineTo()drawCircle())时使用。该填充将保持有效,直到您调用 beginFill()beginBitmapFill()beginGradientFill()beginShaderFill() 方法。调用 clear() 方法会清除填充。

只要绘制 3 个或更多个点,或者调用 endFill() 方法时,应用程序就会呈现填充。

在 GPU 呈现下不支持着色器填充;填充的区域将以蓝绿色着色。

参数

shader:Shader — 要用于填充的着色器。此 Shader 实例无需指定图像输入。但是,如果在着色器中指定图像输入,则必须手动提供输入。要指定输入,请设置 Shader.data 属性的对应 ShaderInput 属性的 input 属性。

传递 Shader 实例作为参数时,会在内部复制着色器。绘图填充操作将使用该内部副本,而不是对原始着色器的引用。对着色器进行的任何更改(比如更改参数值、输入或字节代码)不会应用于所复制的用于填充的着色器。

 
matrix:Matrix (default = null) — 一个 matrix 对象(属于 flash.geom.Matrix 类),可用于对着色器定义转换。例如,可以使用以下矩阵将着色器旋转 45 度(pi/4 弧度):
     matrix = new flash.geom.Matrix(); 
     matrix.rotate(Math.PI / 4);
     

着色器中收到的坐标基于为 matrix 参数指定的矩阵。对于默认 (null) 矩阵,着色器中的坐标是可用于对输入采样的局部像素坐标。


引发
ArgumentError — 当着色器输出类型与此操作不兼容时(着色器必须指定 pixel3pixel4 输出)。
 
ArgumentError — 当着色器指定了未提供的图像输入时。
 
ArgumentError — 当使用 ByteArray 或 Vector.<Number> 实例作为输入,并且没有为 ShaderInput 指定 widthheight 属性或指定的值与输入对象中的数据量不匹配时。有关详细信息,请参阅 ShaderInput.input 属性。

相关 API 元素

clear

()方法 
public function clear():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

清除绘制到此 Graphics 对象的图形,并重置填充和线条样式设置。

copyFrom

()方法 
public function copyFrom(sourceGraphics:Graphics):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5, Flash Lite 4

将源 Graphics 对象中的所有绘图命令复制到执行调用的 Graphics 对象中。

参数

sourceGraphics:Graphics — 从中复制绘图命令的 Graphics 对象。

cubicCurveTo

()方法 
public function cubicCurveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 11, AIR 3

从当前绘图位置到指定的锚点绘制一条三次贝塞尔曲线。三次贝塞尔曲线由两个锚点和两个控制点组成。该曲线内插这两个锚点,并向两个控制点弯曲。

cubic bezier

用于使用 cubicCurveTo() 方法绘制三次贝塞尔曲线的四个点如下所示:

  • 当前绘图位置为首个锚点。
  • anchorXanchorY 参数指定第二个锚点。
  • controlX1controlY1 参数指定首个控制点。
  • controlX2controlY2 参数指定第二个控制点。

如果调用 cubicCurveTo() 方法后才调用 moveTo() 方法,则曲线从位置 (0, 0) 处开始。

如果 cubicCurveTo() 方法成功调用,则 Flash 运行时将当前绘图位置设置为 (anchorX, anchorY)。如果 cubicCurveTo() 方法调用失败,则当前绘图位置保持不变。

如果影片剪辑包含使用 Flash 绘图工具创建的内容,则调用 cubicCurveTo() 方法的结果将在该内容下绘制。

参数

controlX1:Number — 指定首个控制点相对于父显示对象的注册点的水平位置。
 
controlY1:Number — 指定首个控制点相对于父显示对象的注册点的垂直位置。
 
controlX2:Number — 指定第二个控制点相对于父显示对象的注册点的水平位置。
 
controlY2:Number — 指定第二个控制点相对于父显示对象的注册点的垂直位置。
 
anchorX:Number — 指定锚点相对于父显示对象的注册点的水平位置。
 
anchorY:Number — 指定锚点相对于父显示对象的注册点的垂直位置。


示例  ( 如何使用本示例 )

下面的示例在 Sprite 显示对象注册点 (0, 0) 右侧 250 个像素的位置绘制一个蓝色圆形对象,宽度和高度为 100 个像素.

绘制 4 条曲线以生成一个圆,并将其填充为蓝色。

请注意,由于三次贝塞尔方程式所具有的特性,此对象并不是完美的圆。绘制圆的最佳方法是使用 Graphics 类的 drawCircle() 方法。

package {
    import flash.display.Sprite;
    import flash.display.Shape;
    
    public class Graphics_cubicCurveToExample extends Sprite
    {
        public function Graphics_cubicCurveToExample():void
        {
            var rounderObject:Shape = new Shape();

            rounderObject.graphics.beginFill(0x0000FF);
            rounderObject.graphics.moveTo(250, 0);
            rounderObject.graphics.cubicCurveTo(275, 0, 300, 25, 300, 50);
            rounderObject.graphics.cubicCurveTo(300, 75, 275, 100, 250, 100);
            rounderObject.graphics.cubicCurveTo(225, 100, 200, 75, 200, 50);
            rounderObject.graphics.cubicCurveTo(200, 25, 225, 0, 250, 0);
            rounderObject.graphics.endFill();
            
            this.addChild(rounderObject);
        }
    }
}

curveTo

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

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

使用当前线条样式和由 (controlX, controlY) 指定的控制点绘制一条从当前绘图位置开始到 (anchorX, anchorY) 结束的二次贝塞尔曲线。当前绘图位置随后设置为 (anchorX, anchorY)。如果正在其中绘制的影片剪辑包含用 Flash 绘图工具创建的内容,则调用 curveTo() 方法将在该内容下面进行绘制。如果在调用 moveTo() 方法之前调用了 curveTo() 方法,则当前绘图位置的默认值为 (0, 0)。如果缺少任何一个参数,则此方法将失败,并且当前绘图位置不改变。

绘制的曲线是二次贝塞尔曲线。二次贝塞尔曲线包含两个锚点和一个控制点。该曲线内插这两个锚点,并向控制点弯曲。

quadratic bezier

参数

controlX:Number — 一个数字,指定控制点相对于父显示对象注册点的水平位置。
 
controlY:Number — 一个数字,指定控制点相对于父显示对象注册点的垂直位置。
 
anchorX:Number — 一个数字,指定下一个锚点相对于父显示对象注册点的水平位置。
 
anchorY:Number — 一个数字,指定下一个锚点相对于父显示对象注册点的垂直位置。


示例  ( 如何使用本示例 )

下面的示例在 Sprite 显示对象注册点 (0, 0) 右侧 250 个像素的位置绘制一个绿色圆形对象,宽度和高度为 100 个像素。

绘制 4 条曲线以生成一个圆,并将其填充为绿色。

请注意,由于二次贝塞尔方程式所具有的特性,此对象并不是完美的圆。绘制圆的最佳方法是使用 Graphics 类的 drawCircle() 方法。

package {
    import flash.display.Sprite;
    import flash.display.Shape;
    
    public class Graphics_curveToExample1 extends Sprite
    {
        public function Graphics_curveToExample1():void
        {
            var roundObject:Shape = new Shape();

            roundObject.graphics.beginFill(0x00FF00);
            roundObject.graphics.moveTo(250, 0);
            roundObject.graphics.curveTo(300, 0, 300, 50);
            roundObject.graphics.curveTo(300, 100, 250, 100);
            roundObject.graphics.curveTo(200, 100, 200, 50);
            roundObject.graphics.curveTo(200, 0, 250, 0);
            roundObject.graphics.endFill();
            
            this.addChild(roundObject);
        }
    }
}

下面的示例使用 curveTo() 方法绘制一个新月。

绘制两条 1 个像素粗的曲线,并将两条曲线之间的区域填充为白色。moveTo() 方法用于将当前绘制位置放在坐标 (100, 100) 上。第一条曲线将绘制位置移到 (100, 200),这是其目标点。第二条曲线将该位置恢复为开始位置 (100, 100),这是其目标点。水平控制点决定了不同的曲线大小。

package {
    import flash.display.Sprite;
    import flash.display.Shape;

    public class Graphics_curveToExample2 extends Sprite
    {
        public function Graphics_curveToExample2() {
            var newMoon:Shape = new Shape();
            
            newMoon.graphics.lineStyle(1, 0);
            newMoon.graphics.beginFill(0xFFFFFF);
            newMoon.graphics.moveTo(100, 100); 
            newMoon.graphics.curveTo(30, 150, 100, 200);    
            newMoon.graphics.curveTo(50, 150, 100, 100);
            graphics.endFill();
            
            this.addChild(newMoon);
        }
    }
}

drawCircle

()方法 
public function drawCircle(x:Number, y:Number, radius:Number):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

绘制一个圆。在调用 drawCircle() 方法之前,通过调用 linestyle()lineGradientStyle()beginFill()beginGradientFill()beginBitmapFill() 方法来设置线条样式或/和填充。

参数

x:Number — 圆心相对于父显示对象注册点的 x 位置(以像素为单位)。
 
y:Number — 相对于父显示对象注册点的圆心的 y 位置(以像素为单位)。
 
radius:Number — 圆的半径(以像素为单位)。

相关 API 元素


示例
如何使用本示例
有关如何使用此方法的说明,请参阅此类末尾的示例

drawEllipse

()方法 
public function drawEllipse(x:Number, y:Number, width:Number, height:Number):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

绘制一个椭圆。在调用 drawEllipse() 方法之前,通过调用 linestyle()lineGradientStyle()beginFill()beginGradientFill()beginBitmapFill() 方法来设置线条样式或/和填充。

参数

x:Number — 椭圆边框左上角相对于父显示对象注册点的 x 位置(以像素为单位)。
 
y:Number — 椭圆边框左上角相对于父显示对象注册点的 y 位置(以像素为单位)。
 
width:Number — 椭圆的宽度(以像素为单位)。
 
height:Number — 椭圆的高度(以像素为单位)。

相关 API 元素


示例  ( 如何使用本示例 )

下面的示例使用 drawEgg() 函数绘制三个不同大小的鸡蛋(三种尺寸的椭圆),具体取决于 eggSize 参数。
  1. 构造函数调用 drawEgg() 函数,并为应该绘制鸡蛋的位置传递水平和垂直参数以及鸡蛋类型 (eggSize)。(可使用鸡蛋(椭圆形)高度和宽度来确定其显示位置。)
  2. drawEgg() 函数绘制不同大小的椭圆,并使用 beginFill() 方法将其填充为白色。没有事先为此函数编写错误处理代码。
package {
    import flash.display.Sprite;
    import flash.display.Shape;

    public class Graphics_drawEllipseExample extends Sprite
    {
        public static const SMALL:uint = 0;
        public static const MEDIUM:uint = 1;
        public static const LARGE:uint = 2;

        public function Graphics_drawEllipseExample()
        {
            drawEgg(SMALL, 0, 100);
            drawEgg(MEDIUM, 100, 60);
            drawEgg(LARGE, 250, 35);    
        }

        public function drawEgg(eggSize:uint, x:Number, y:Number):void  {
            
            var myEgg:Shape = new Shape();
            
            myEgg.graphics.beginFill(0xFFFFFF);
            myEgg.graphics.lineStyle(1);

            switch(eggSize) {
                case SMALL:
                    myEgg.graphics.drawEllipse(x, y, 60, 70);
                    break;
                case MEDIUM:
                    myEgg.graphics.drawEllipse(x, y, 120, 150);    
                    break;
                case LARGE:
                    myEgg.graphics.drawEllipse(x, y, 150, 200);
                    break;
                default:
                    trace ("Wrong size! There is no egg.");
                break;            
            }
            
            myEgg.graphics.endFill();
    
            this.addChild(myEgg);
        }
    }
}

drawGraphicsData

()方法 
public function drawGraphicsData(graphicsData:Vector.<IGraphicsData>):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5

提交一系列 IGraphicsData 实例来进行绘图。此方法接受一个包含对象(包括路径、填充和笔触)的矢量,这些对象实现 IGraphicsData 接口。包含 IGraphicsData 实例的矢量可以引用形状的一部分,或引用一组完整定义的复杂数据以呈现完整的形状。

图形路径可以包含其他图形路径。如果 graphicsData 矢量包括路径,则在此操作期间将呈现该路径及其所有子路径。

参数

graphicsData:Vector.<IGraphicsData> — 一个包含图形对象的矢量,其中的每个对象都必须实现 IGraphicsData 接口。

相关 API 元素


示例  ( 如何使用本示例 )

以下示例创建了一个 GraphicsGradientFill 对象,用于建立正方形的填充属性。然后,该示例创建了一个 GraphicsStroke 对象(表示线宽)和一个 GraphicsSolidFill 对象(表示线色),用于设置正方形边框线的属性。然后,本示例创建一个 GraphicsPath 对象,以包含用于绘制形状的值。所有这些对象都存储在 IGraphicsData 对象中,并传递给 drawGraphicsData() 命令以呈现形状。
package
{
    import flash.display.*;
    import flash.geom.*;

    public class DrawGraphicsDataExample extends Sprite
    {
        public function DrawGraphicsDataExample()
        {
            // establish the fill properties
            var myFill:GraphicsGradientFill = new GraphicsGradientFill();
            myFill.colors = [0xEEFFEE, 0x0000FF];
            myFill.matrix = new Matrix();
            myFill.matrix.createGradientBox(100, 100, 0);
            
            // establish the stroke properties
            var myStroke:GraphicsStroke = new GraphicsStroke(2);
            myStroke.fill = new GraphicsSolidFill(0x000000);
            
            // establish the path properties
            var pathCommands = new Vector.<int>(5, true);
            pathCommands[0] = GraphicsPathCommand.MOVE_TO;
            pathCommands[1] = GraphicsPathCommand.LINE_TO;
            pathCommands[2] = GraphicsPathCommand.LINE_TO;
            pathCommands[3] = GraphicsPathCommand.LINE_TO;
            pathCommands[4] = GraphicsPathCommand.LINE_TO;
            
            var pathCoordinates:Vector.<Number> = new Vector.<Number>(10, true);
            pathCoordinates.push(10,10, 10,100, 100,100, 100,10, 10,10);
            
            var myPath:GraphicsPath = new GraphicsPath(pathCommands, pathCoordinates);
            
            // populate the IGraphicsData Vector array
            var myDrawing:Vector.<IGraphicsData> = new Vector.<IGraphicsData>(3, true);
            myDrawing[0] = myFill;
            myDrawing[1] = myStroke;
            myDrawing[2] = myPath;
            
            // render the drawing
            graphics.drawGraphicsData(myDrawing);
        }
    }
}

drawPath

()方法 
public function drawPath(commands:Vector.<int>, data:Vector.<Number>, winding:String = "evenOdd"):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5

提交一系列绘制命令。drawPath() 方法接受一个矢量,它由单个的 moveTo()lineTo()curveTo() 绘图命令构成,这三个命令合并为一个单独的调用。drawPath() 方法参数将绘图命令与 x 和 y 坐标值对以及绘图方向组合起来。这几个绘图命令是整数,表示为 GraphicsPathCommand 类中定义的常量。x 和 y 坐标值对是数组中的数字,其中的每对数字定义一个坐标位置。绘图方向为 GraphicsPathWinding 类中的值。

通常,与使用一系列单个 lineTo()curveTo() 方法调用相比,使用 drawPath() 呈现绘图的速度会更快。

drawPath() 方法使用浮动计算,因此形状的旋转和缩放更准确,可以获得更好的结果。但是,通过使用 drawPath() 方法提交的曲线在与 lineTo()curveTo() 方法结合使用时,可能会存在小的子像素对齐误差。

drawPath() 方法还使用稍有不同的规则进行填充和绘制线条。这些规则是:

  • 在应用填充以呈现路径时:
    • 不呈现少于 3 个点的子路径。(但请注意,笔触呈现仍将发生,并与下面的笔触规则相一致。)
    • 隐式闭合未闭合的子路径(结束点不等于开始点)。
  • 在应用笔触以呈现路径时:
    • 子路径可以由任何数量的点组成。
    • 从不隐式闭合子路径。

参数

commands:Vector.<int> — 由表示绘图命令的整数构成的矢量。可接受的值集由 GraphicsPathCommand 类中的常量定义。
 
data:Vector.<Number> — 由数字实例构成的矢量,其中的每一对数字将被视为一个坐标位置(一个 x, y 对)。x 和 y 坐标值对不是 Point 对象;data 矢量是一系列数字,其中的每个由两个数字构成的组表示一个坐标位置。
 
winding:String (default = "evenOdd") — 使用 GraphicsPathWinding 类中定义的值指定缠绕规则。

相关 API 元素


示例  ( 如何使用本示例 )

下面的示例填充两个 Vector 对象,然后将其传递给 drawPath() 方法以呈现一个蓝星。第一个矢量 star_commands 包含 GraphicsPathCommand 类中表示绘图命令的一系列常量。第二个 Vector 对象 star_coord 包含 5 组 x 和 y 坐标对。drawPath() 方法将命令与位置进行匹配以绘制一个星形。
package
{
    import flash.display.*;
        
    public class DrawPathExample extends Sprite
    {
        public function DrawPathExample()
        {
            var star_commands:Vector.<int> = new Vector.<int>(5, true);
            
            star_commands[0] = GraphicsPathCommand.MOVE_TO;
            star_commands[1] = GraphicsPathCommand.LINE_TO;
            star_commands[2] = GraphicsPathCommand.LINE_TO;
            star_commands[3] = GraphicsPathCommand.LINE_TO;
            star_commands[4] = GraphicsPathCommand.LINE_TO;
            
            var star_coord:Vector.<Number> = new Vector.<Number>(10, true);
            star_coord[0] = 66; //x
            star_coord[1] = 10; //y 
            star_coord[2] = 23; 
            star_coord[3] = 127; 
            star_coord[4] = 122; 
            star_coord[5] = 50; 
            star_coord[6] = 10; 
            star_coord[7] = 49; 
            star_coord[8] = 109; 
            star_coord[9] = 127;
            
            graphics.beginFill(0x003366);
            graphics.drawPath(star_commands, star_coord);
        }
    }
}

注意:默认情况下,drawPath() 方法使用奇偶缠绕类型。因此,不会填充星形的中心。若想填充星形的中心,可对第三个参数指定非零缠绕类型:
 graphics.drawPath(star_commands, star_coord, GraphicsPathWinding.NON_ZERO);
 

drawRect

()方法 
public function drawRect(x:Number, y:Number, width:Number, height:Number):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

绘制一个矩形。在调用 drawRect() 方法之前,通过调用 linestyle()lineGradientStyle()beginFill()beginGradientFill()beginBitmapFill() 方法来设置线条样式或/和填充。

参数

x:Number — 一个表示相对于父显示对象注册点的水平位置的数字(以像素为单位)。
 
y:Number — 一个表示相对于父显示对象注册点的垂直位置的数字(以像素为单位)。
 
width:Number — 矩形的宽度(以像素为单位)。
 
height:Number — 矩形的高度(以像素为单位)。


引发
ArgumentError — 如果 widthheight 参数不是数值 (Number.NaN)。

相关 API 元素


示例  ( 如何使用本示例 )

以下示例显示如何在 ActionScript 3.0 中绘制形状。ActionScriptExamples.com 提供的示例。
var movieClip:MovieClip = new MovieClip();
movieClip.graphics.beginFill(0xFF0000);
movieClip.graphics.drawRect(0, 0, 100, 80);
movieClip.graphics.endFill();
movieClip.x = 10;
movieClip.y = 10;
addChild(movieClip);

drawRoundRect

()方法 
public function drawRoundRect(x:Number, y:Number, width:Number, height:Number, ellipseWidth:Number, ellipseHeight:Number = NaN):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

绘制一个圆角矩形。在调用 drawRoundRect() 方法之前,通过调用 linestyle()lineGradientStyle()beginFill()beginGradientFill()beginBitmapFill() 方法来设置线条样式或/和填充。

参数

x:Number — 一个表示相对于父显示对象注册点的水平位置的数字(以像素为单位)。
 
y:Number — 一个表示相对于父显示对象注册点的垂直位置的数字(以像素为单位)。
 
width:Number — 圆角矩形的宽度(以像素为单位)。
 
height:Number — 圆角矩形的高度(以像素为单位)。
 
ellipseWidth:Number — 用于绘制圆角的椭圆的宽度(以像素为单位)。
 
ellipseHeight:Number (default = NaN) — 用于绘制圆角的椭圆的高度(以像素为单位)。(可选)如果未指定值,则默认值与为 ellipseWidth 参数提供的值相匹配。


引发
ArgumentError — 如果 widthheightellipseWidthellipseHeight 参数不是数值 (Number.NaN)。

相关 API 元素


示例
如何使用本示例
有关如何使用此方法的说明,请参阅此类末尾的示例

drawTriangles

()方法 
public function drawTriangles(vertices:Vector.<Number>, indices:Vector.<int> = null, uvtData:Vector.<Number> = null, culling:String = "none"):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5

呈现一组三角形(通常用于扭曲位图),并为其指定三维外观。drawTriangles() 方法使用一组 (u,v) 坐标将当前填充或位图填充映射到三角形面。

可以使用任何类型的填充,但如果填充有转换矩阵,则将忽略该转换矩阵。

在使用位图填充时,uvtData 参数可改善纹理映射。

参数

vertices:Vector.<Number> — 由数字构成的矢量,其中的每一对数字将被视为一个坐标位置(一个 x, y 对)。vertices 参数是必需的。
 
indices:Vector.<int> (default = null) — 一个由整数或索引构成的矢量,其中每三个索引定义一个三角形。如果 indexes 参数为 null,则每三个顶点(vertices 矢量中的 6 对 x,y)定义一个三角形。否则,每个索引将引用一个顶点,即 vertices 矢量中的一对数字。例如,indexes[1] 引用 (vertices[2], vertices[3])。indexes 参数是可选的,但 indexes 通常会减少提交的数据量和计算的数据量。
 
uvtData:Vector.<Number> (default = null) — 由用于应用纹理映射的标准坐标构成的矢量。每个坐标引用用于填充的位图上的一个点。每个顶点必须具有一个 UV 或一个 UVT 坐标。对于 UV 坐标,(0,0) 是位图的左上角,(1,1) 是位图的右下角。

如果此矢量的长度是 vertices 矢量长度的两倍,则使用标准坐标而不进行透视校正。

如果此矢量的长度是 vertices 矢量长度的三倍,则将第三个坐标解释为“t”(即在视角空间中从视点到纹理的距离)。这有助于呈现引擎在三维中映射纹理时正确应用透视。

如果 uvtData 参数为 null,则将应用普通填充规则(和任何填充类型)。

 
culling:String (default = "none") — 指定是否呈现面向指定方向的三角形。此参数可防止呈现在当前视图中看不见的三角形。此参数可设置为由 TriangleCulling 类定义的任何值。

相关 API 元素

endFill

()方法 
public function endFill():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

对从上一次调用 beginFill()beginGradientFill()beginBitmapFill() 方法之后添加的直线和曲线应用填充。Flash 使用的是对 beginFill()beginGradientFill()beginBitmapFill() 方法的先前调用中指定的填充。如果当前绘图位置不等于 moveTo() 方法中指定的上一个位置,而且定义了填充,则用线条闭合该路径,然后进行填充。

相关 API 元素

lineBitmapStyle

()方法 
public function lineBitmapStyle(bitmap:BitmapData, matrix:Matrix = null, repeat:Boolean = true, smooth:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5

指定一个位图,用于绘制线条时的线条笔触。

位图线条样式将用于随后对 lineTo()drawCircle() 等 Graphics 方法的调用。线条样式仍然有效,直到您使用不同的参数调用 lineStyle()lineGradientStyle() 方法或再次调用 lineBitmapStyle() 方法。

可以在绘制路径的中间调用 lineBitmapStyle() 方法以为路径中的不同线段指定不同的样式。

请在调用 lineBitmapStyle() 方法之前调用 lineStyle() 方法以启用笔触,否则线条样式的值将为 undefined

调用 clear() 方法会将线条样式设置回 undefined

参数

bitmap:BitmapData — 用于线条笔触的位图。
 
matrix:Matrix (default = null) — 一个由 flash.geom.Matrix 类定义的可选转换矩阵。该矩阵可用于在将位图应用于线条样式之前缩放位图或以其他方式处理位图。
 
repeat:Boolean (default = true) — 是否以平铺方式重复位图。
 
smooth:Boolean (default = false) — 是否应对位图应用平滑处理。

相关 API 元素

lineGradientStyle

()方法 
public function lineGradientStyle(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9

指定一种渐变,用于绘制线条时的笔触。

渐变线条样式将用于随后对 lineTo()drawCircle() 等 Graphics 方法的调用。线条样式仍然有效,直到您使用不同的参数调用 lineStyle()lineBitmapStyle() 方法或再次调用 lineGradientStyle() 方法。

可以在绘制路径的中间调用 lineGradientStyle() 方法以为路径中的不同线段指定不同的样式。

请在调用 lineGradientStyle() 方法之前调用 lineStyle() 方法以启用笔触,否则线条样式的值将为 undefined

调用 clear() 方法会将线条样式设置回 undefined

参数

type:String — 用于指定要使用哪种渐变类型的 GradientType 类的值:GradientType.LINEAR 或 GradientType.RADIAL。
 
colors:Array — 要在渐变中使用的 RGB 十六进制颜色值数组(例如,红色为 0xFF0000,蓝色为 0x0000FF 等等)。
 
alphas:Array — colors 数组中对应颜色的 alpha 值数组;有效值为 0 到 1。如果值小于 0,则默认值为 0。如果值大于 1,则默认值为 1。
 
ratios:Array — 颜色分布比率的数组;有效值为 0 到 255。该值定义 100% 采样的颜色所在位置的宽度百分比。值 0 表示渐变框中的左侧位置,255 表示渐变框中的右侧位置。此值表示渐变框中的位置,而不是最终渐变的坐标空间,最终渐变可能会比渐变框更宽或更窄。为 colors 参数中的每个值指定一个值。

例如,对于包含蓝和绿两种颜色的线性渐变,下图显示了基于不同 ratios 数组值的颜色配比:

ratios渐变
[0, 127]ratios 为 0 和 127 时蓝色到绿色的线性渐变
[0, 255]ratios 为 0 和 255 时蓝色到绿色的线性渐变
[127, 255]ratios 为 127 和 255 时蓝色到绿色的线性渐变

数组中的值必须持续增加;例如,[0, 63, 127, 190, 255]

 
matrix:Matrix (default = null) — 一个由 flash.geom.Matrix 类定义的转换矩阵。flash.geom.Matrix 类包括 createGradientBox() 方法,通过该方法可以方便地设置矩阵,以便与 lineGradientStyle() 方法一起使用。
 
spreadMethod:String (default = "pad") — 用于指定要使用哪种 spread 方法的 SpreadMethod 类的值:

以 SpreadMethod.PAD 线性渐变以 SpreadMethod.REFLECT 线性渐变以 SpreadMethod.REPEAT 线性渐变
SpreadMethod.PADSpreadMethod.REFLECTSpreadMethod.REPEAT

 
interpolationMethod:String (default = "rgb") — InterpolationMethod 类中用于指定要使用的值的值。例如,假设有两种颜色之间的简单线性渐变(spreadMethod 参数设置为 SpreadMethod.REFLECT)。不同的插值方法对外观的影响如下所示:

以 InterpolationMethod.LINEAR_RGB 线性渐变以 InterpolationMethod.RGB 线性渐变
InterpolationMethod.LINEAR_RGBInterpolationMethod.RGB

 
focalPointRatio:Number (default = 0) — 一个控制渐变的焦点位置的数字。值 0 表示焦点位于中心。值 1 表示焦点位于渐变圆的一条边界上。值 -1 表示焦点位于渐变圆的另一条边界上。小于 -1 或大于 1 的值将舍入为 -1 或 1。下列图像显示 focalPointRatio 为 -0.75 的渐变:

focalPointRatio 设置为 0.75 时的放射状渐变

相关 API 元素


示例  ( 如何使用本示例 )

下面的示例绘制一个矩形和一个圆,它们使用从红色到绿色、再到蓝色的渐变笔触。

Matrix 类中的方法 createGradientBox() 用于将渐变框定义为 200 个像素宽、40 个像素高。线条粗细设置为 5 个像素。必须为 lineGradientStyle() 方法定义笔触粗细。渐变设置为线性。渐变颜色设置为红色、绿色和蓝色。颜色透明度(Alpha 值)设置为 1(不透明)。渐变的分布是均匀的,其中在 0(渐变框中的左侧位置)、128(渐变框的中间位置)和 255(渐变框中的右侧位置)处的颜色采样率为 100%。矩形宽度范围内包含渐变的所有色谱;而圆包含色谱中间的 50%。

package {
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.geom.Matrix; 
    import flash.display.GradientType;
    
    public class Graphics_lineGradientStyleExample extends Sprite
    {
        public function Graphics_lineGradientStyleExample()
        {
            var myShape:Shape = new Shape();
            var gradientBoxMatrix:Matrix = new Matrix();
  
            gradientBoxMatrix.createGradientBox(200, 40, 0, 0, 0);  
            
            myShape.graphics.lineStyle(5);
  
            myShape.graphics.lineGradientStyle(GradientType.LINEAR, [0xFF0000,
            0x00FF00, 0x0000FF], [1, 1, 1], [0, 128, 255], gradientBoxMatrix);
            
            myShape.graphics.drawRect(0, 0, 200, 40);
            myShape.graphics.drawCircle(100, 120, 50);  
             
            this.addChild(myShape);
    
        }
    }
}

lineShaderStyle

()方法 
public function lineShaderStyle(shader:Shader, matrix:Matrix = null):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5

指定一个着色器以用于绘制线条时的线条笔触。

着色器线条样式将用于随后对 lineTo()drawCircle() 等 Graphics 方法的调用。线条样式仍然有效,直到您使用不同的参数调用 lineStyle()lineGradientStyle() 方法或再次调用 lineBitmapStyle() 方法。

可以在绘制路径的中间调用 lineShaderStyle() 方法,以便为路径中的不同线段指定不同的样式。

请在调用 lineShaderStyle() 方法之前调用 lineStyle() 方法以启用笔触,否则线条样式的值将为 undefined

调用 clear() 方法会将线条样式设置回 undefined

参数

shader:Shader — 用于线条笔触的着色器。
 
matrix:Matrix (default = null) — 一个由 flash.geom.Matrix 类定义的可选转换矩阵。该矩阵可用于在将位图应用于线条样式之前缩放位图或以其他方式处理位图。

相关 API 元素

lineStyle

()方法 
public function lineStyle(thickness:Number = NaN, color:uint = 0, alpha:Number = 1.0, pixelHinting:Boolean = false, scaleMode:String = "normal", caps:String = null, joints:String = null, miterLimit:Number = 3):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

指定一种线条样式以用于随后对 lineTo()drawCircle() 等 Graphics 方法的调用。线条样式仍然有效,直到您使用不同的参数调用 lineGradientStyle() 方法、lineBitmapStyle() 方法或 lineStyle() 方法。

可以在绘制路径的中间调用 lineStyle() 方法以为路径中的不同线段指定不同的样式。

注意:调用 clear() 方法会将线条样式设置回 undefined

注意:Flash Lite 4 仅支持前 3 个参数(thicknesscoloralpha)。

参数

thickness:Number (default = NaN) — 一个整数,以点为单位表示线条的粗细;有效值为 0 到 255。如果未指定数字,或者未定义该参数,则不绘制线条。如果传递的值小于 0,则默认值为 0。值 0 表示极细的粗细;最大粗细为 255。如果传递的值大于 255,则默认值为 255。
 
color:uint (default = 0) — 线条的十六进制颜色值(例如,红色为 0xFF0000,蓝色为 0x0000FF 等)。如果未指明值,则默认值为 0x000000(黑色)。可选。
 
alpha:Number (default = 1.0) — 表示线条颜色的 Alpha 值的数字;有效值为 0 到 1。如果未指明值,则默认值为 1(纯色)。如果值小于 0,则默认值为 0。如果值大于 1,则默认值为 1。
 
pixelHinting:Boolean (default = false) — (在 Flash Lite 4 中不受支持)布尔型值,指定是否提示笔触采用完整像素。它同时影响曲线锚点的位置以及线条笔触大小本身。在 pixelHinting 设置为 true 的情况下,线条宽度会调整到完整像素宽度。在 pixelHinting 设置为 false 的情况下,对于曲线和直线可能会出现脱节。例如,下面的插图显示了 Flash Player 或 Adobe AIR 如何呈现两个相同的圆角矩形,不同之处是 lineStyle() 方法中使用的 pixelHinting 参数的设置不同(图像已放大 200% 以强调差异):

pixelHinting 为 false,pixelHinting 为 true

如果未提供值,则线条不使用像素提示。

 
scaleMode:String (default = "normal") — (在 Flash Lite 4 中不支持)LineScaleMode 类的值,用于指定要使用的比例模式:
  • LineScaleMode.NORMAL -- 在缩放对象时总是缩放线条的粗细(默认值)。
  • LineScaleMode.NONE -- 从不缩放线条粗细。
  • LineScaleMode.VERTICAL -- 如果 垂直缩放对象,则不缩放线条粗细。例如,考虑下面的圆形,它们是用一个像素的线条绘制的,每个圆的 scaleMode 参数都被设置为 LineScaleMode.VERTICAL。左边的圆仅在垂直方向上缩放,而右边的圆则同时在垂直和水平方向上缩放:

    一个在垂直方向缩放的圆和一个在垂直和水平方向同时缩放的圆。

  • LineScaleMode.HORIZONTAL -- 如果 水平缩放对象,则不缩放线条粗细。例如,考虑下面的圆形,它们是用一个像素的线条绘制的,每个圆的 scaleMode 参数都被设置为 LineScaleMode.HORIZONTAL。左边的圆仅在水平方向上缩放,而右边的圆则同时在垂直和水平方向上缩放:

    一个在水平方向缩放的圆和一个在水平和垂直方向同时缩放的圆。

 
caps:String (default = null) — (在 Flash Lite 4 中不支持)用于指定线条末端处端点类型的 CapsStyle 类的值。有效值为:CapsStyle.NONECapsStyle.ROUNDCapsStyle.SQUARE。如果未表示值,则 Flash 使用圆头端点。

例如,以下图示显示了不同的 capsStyle 设置。对于每种设置,插图显示了一条粗细为 30 的蓝色线条(应用 capsStyle 的线条),以及重叠于其上的粗细为 1 的黑色线条(未应用 capsStyle 的线条):

NONE、ROUND 和 SQUARE

 
joints:String (default = null) — (在 Flash Lite 4 中不支持)JointStyle 类的值,指定用于拐角的连接外观的类型。有效值为:JointStyle.BEVELJointStyle.MITERJointStyle.ROUND。如果未表示值,则 Flash 使用圆角连接。

例如,以下图示显示了不同的 joints 设置。对于每种设置,插图显示了一条粗细为 30 的带拐角的蓝色线条(应用 jointStyle 的线条),以及重叠于其上的粗细为 1 的带拐角的黑色线条(未应用 jointStyle 的线条):

MITER、ROUND 和 BEVEL

注意:对于设置为 JointStyle.MITERjoints,您可以使用 miterLimit 参数限制尖角的长度。

 
miterLimit:Number (default = 3) — (在 Flash Lite 4 中不支持)用于表示剪切斜接的极限值的数字。有效值的范围是 1 到 255(超出该范围的值将舍入为 1 或 255)。此值只可用于 jointStyle 设置为 "miter" 的情况下。miterLimit 值表示向外延伸的尖角可以超出角边相交所形成的结合点的长度。此值表示为线条 thickness 的因子。例如,miterLimit 因子为 2.5 且 thickness 为 10 像素时,尖角将在 25 像素处切断。

例如,请考虑下列带拐角的线条,每个线条都以 thickness 20 进行绘制,但它们的 miterLimit 分别设置为 1、2 和 4。重叠在其上的黑色参考线条显示了结合处的联结点:

miterLimit 设置为 1、2 和 4 的线条

请注意,对于给定的 miterLimit 值,会有一个被切断的尖角的特定最大角度。下表列出了部分示例:

miterLimit 值:小于此角度将被切断:
1.41490 度
260 度
430 度
815 度

相关 API 元素


示例
如何使用本示例
有关如何使用 getStyle() 方法的说明,请参阅 lineTo()moveTo() 方法的示例。

lineTo

()方法 
public function lineTo(x:Number, y:Number):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

使用当前线条样式绘制一条从当前绘图位置开始到 (x, y) 结束的直线;当前绘图位置随后会设置为 (x, y)。如果正在其中绘制的显示对象包含用 Flash 绘图工具创建的内容,则调用 lineTo() 方法将在该内容下面进行绘制。如果在对 moveTo() 方法进行任何调用之前调用了 lineTo(),则当前绘图的默认位置为 (0, 0)。如果缺少任何一个参数,则此方法将失败,并且当前绘图位置不改变。

参数

x:Number — 一个表示相对于父显示对象注册点的水平位置的数字(以像素为单位)。
 
y:Number — 一个表示相对于父显示对象注册点的垂直位置的数字(以像素为单位)。


示例  ( 如何使用本示例 )

下面的示例使用 lineTo() 方法绘制一个梯形,从像素 (100, 100) 开始。

线条粗细设置为 10 个像素,颜色为金色且不透明,线条终点设置为 none(因为联接了所有线条),两条线之间的联接点设置为 MITER 并将尖角限制设置为 10 以绘制尖锐的边角。

package {
    import flash.display.Sprite;
    import flash.display.LineScaleMode;
    import flash.display.CapsStyle;
    import flash.display.JointStyle;
    import flash.display.Shape;


    public class Graphics_lineToExample extends Sprite {

        public function Graphics_lineToExample() {

            var trapezoid:Shape = new Shape();    

            trapezoid.graphics.lineStyle(10, 0xFFD700, 1, false, LineScaleMode.VERTICAL,
                               CapsStyle.NONE, JointStyle.MITER, 10);

            trapezoid.graphics.moveTo(100, 100);
 
            trapezoid.graphics.lineTo(120, 50);
            trapezoid.graphics.lineTo(200, 50);
            trapezoid.graphics.lineTo(220, 100);
            trapezoid.graphics.lineTo(100, 100); 

            this.addChild(trapezoid);
        }
    }
}

moveTo

()方法 
public function moveTo(x:Number, y:Number):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将当前绘图位置移动到 (x, y)。如果缺少任何一个参数,则此方法将失败,并且当前绘图位置不改变。

参数

x:Number — 一个表示相对于父显示对象注册点的水平位置的数字(以像素为单位)。
 
y:Number — 一个表示相对于父显示对象注册点的垂直位置的数字(以像素为单位)。


示例  ( 如何使用本示例 )

下面的示例使用 moveTo()lineTo() 方法绘制一条 3 个像素粗的虚线。

通过使用 lineStyle() 方法,将线条粗细设置为 3 个像素。还将其设置为不进行缩放。颜色设置为红色,并且不透明度为 25%。CapsStyle 属性设置为 square(默认值为 round)。

由于 Graphics_moveToExampleSprite 类实例,因此,它具有所有 Graphics 类方法的访问权限。可以使用 Graphics 类方法直接在 Graphic_moveToExample Sprite 对象上进行绘制。但是,如果未将矢量绘画对象放在 Shape 中,则会限制它们的管理、移动或更改方式。

package {
    import flash.display.Sprite;
    import flash.display.CapsStyle;
    import flash.display.LineScaleMode;

    public class Graphics_moveToExample extends Sprite
    {
        public function Graphics_moveToExample() {
            
            graphics.lineStyle(3, 0x990000, 0.25, false, 
                            LineScaleMode.NONE, CapsStyle.SQUARE);

            graphics.moveTo(10, 20);
            graphics.lineTo(20, 20);
            graphics.moveTo(30, 20);
            graphics.lineTo(50, 20);
            graphics.moveTo(60, 20);
            graphics.lineTo(80, 20);
            graphics.moveTo(90, 20);
            graphics.lineTo(110, 20);            
            graphics.moveTo(120, 20);
            graphics.lineTo(130, 20);           
        }
    }
}

readGraphicsData

()方法 
public function readGraphicsData(recurse:Boolean = true):Vector.<IGraphicsData>

语言版本: ActionScript 3.0
运行时版本: Flash Player 11.6, AIR 3.6

查询 Sprite 或 Shape 对象(也可以是其子对象)的矢量图形内容。结果是一个由 IGraphicsData 对象构成的矢量。转换是在进行查询之前应用到显示对象的,因此返回路径全部在同一坐标空间中。结果数据集中的坐标是相对于舞台的,而不是相对于进行采样的显示对象。

结果包括以下类型的对象,并具有指定限制:

  • GraphicsSolidFill
  • GraphicsGradientFill
    • 渐变填充的所有属性由 readGraphicsData() 返回。
    • 返回的矩阵接近输入矩阵,但不完全等同。
  • GraphicsEndFill
  • GraphicsBitmapFill
    • 返回的矩阵接近输入矩阵,但不完全等同。
    • repeat 始终为 true。
    • smooth 始终为 false。
  • GraphicsStroke
    • 支持 thickness
    • 如前所述,fill 支持 GraphicsSolidFill、GraphicsGradientFill 及 GraphicsBitmapFill
    • 所有其他属性均有默认值。
  • GraphicsPath
    • 仅支持 MOVE_TO、CURVE_TO 和 LINE_TO 命令。

无法表示以下可视元素和转换,因此它们不会包括在结果中:

  • 屏蔽
  • 文本,但有一个例外:用消除锯齿类型“动画消除锯齿”定义的静态文本将作为矢量图形呈现,因此包括在结果中。
  • 着色器填充
  • 混合模式
  • 9 切片缩放
  • 三角形(用 drawTriangles() 方法创建)
  • 不透明的背景
  • scrollrect 设置
  • 2.5D 转换
  • 非可见对象(其 visible 属性为 false 的对象)

参数

recurse:Boolean (default = true) — 运行时是否还应查询当前显示对象的子对象。执行递归查询会花费更多的时间和内存。查询结果将以单一的拼合结果集返回,不会按显示对象分隔开。

返回
Vector.<IGraphicsData> — 由 IGraphicsData 对象构成的矢量,表示相关显示对象的矢量图形内容

相关 API 元素


示例  ( 如何使用本示例 )

下例使用 readGraphicsData() 方法来检索显示对象的矢量图形内容。然后在用户用鼠标单击舞台时,将该内容重新绘制到舞台上的另一个对象中。

请注意,尽管原来的矢量内容是用 drawGraphicsData() 方法绘制的,但由 readGraphicsData() 方法检索出的矢量数据对象并不与传递到 drawGraphicsData() 方法中的矢量数据对象完全匹配。例如,结果数据包括 GraphicsSolidFill 和 GraphicsEndFill 命令,这两个命令是隐含的,并不实际存在于原来的图形数据中。

package
{
    import flash.display.GraphicsPathCommand;
    import flash.display.IGraphicsData;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    
    public class ReadGraphicsDataExample extends Sprite
    {
        private var original:Shape;
        private var copy:Shape;
        
        public function ReadGraphicsDataExample()
        {
            original = new Shape();
            original.x = 50;
            original.y = 100;
            addChild(original);
            
            drawSquare();
            
            copy = new Shape();
            copy.x = 250;
            copy.y = 100;
            addChild(copy);
            
            stage.addEventListener(MouseEvent.CLICK, drawCopyOnClick);
        }
        
        private function drawCopyOnClick(event:MouseEvent):void
        {
            // reset
            copy.graphics.clear();
            
            // Sample the vector data. Move the original to 0,0
            // before sampling so that the coordinates match the 
            // relative coordinates of the original.
            var xPos:Number = original.x;
            var yPos:Number = original.y;
            original.x = 0;
            original.y = 0;
            var result:Vector.<IGraphicsData> = original.graphics.readGraphicsData(false);
            original.x = xPos;
            original.y = yPos;
            
            // re-draw
            copy.graphics.drawGraphicsData(result);
        }
        
        private function drawSquare():void
        {
            var squareCommands:Vector.<int> = new Vector.<int>(5, true);
            
            squareCommands[0] = GraphicsPathCommand.MOVE_TO;
            squareCommands[1] = GraphicsPathCommand.LINE_TO;
            squareCommands[2] = GraphicsPathCommand.LINE_TO;
            squareCommands[3] = GraphicsPathCommand.LINE_TO;
            
            var squareCoordinates:Vector.<Number> = new Vector.<Number>(8, true);
            squareCoordinates[0] = 0;
            squareCoordinates[1] = 0; 
            squareCoordinates[2] = 50; 
            squareCoordinates[3] = 0; 
            squareCoordinates[4] = 50; 
            squareCoordinates[5] = 50; 
            squareCoordinates[6] = 0; 
            squareCoordinates[7] = 50; 
            
            original.graphics.beginFill(0x003366);
            original.graphics.drawPath(squareCommands, squareCoordinates);
        }
    }
}
GraphicsExample.as

下例使用 GraphicsExample 类绘制圆形、圆角矩形和正方形。执行下列步骤可完成该任务:
  1. 声明 size 属性以备日后在确定每个形状的大小时使用。
  2. 声明以下属性:将背景色设置为橙色、将边框颜色设置为深灰色、将边框大小设置为 0 个像素、将角半径设置为 9 个像素并将舞台边缘与其他对象之间的间距设置为 5 个像素。
  3. 使用在前面步骤中声明的属性以及使用 Graphics 类的内置方法,可在坐标 x = 0, y = 0 处绘制圆形、圆角矩形和正方形。
  4. 沿舞台顶部重新绘制每个形状,起点为 x = 5,y = 5,各形状之间的间隔为 5 个像素。
package {
    import flash.display.DisplayObject;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;

    public class GraphicsExample extends Sprite {
        private var size:uint         = 80;
        private var bgColor:uint      = 0xFFCC00;
        private var borderColor:uint  = 0x666666;
        private var borderSize:uint   = 0;
        private var cornerRadius:uint = 9;
        private var gutter:uint       = 5;

        public function GraphicsExample() {
            doDrawCircle();
            doDrawRoundRect();
            doDrawRect();
            refreshLayout();
        }

        private function refreshLayout():void {
            var ln:uint = numChildren;
            var child:DisplayObject;
            var lastChild:DisplayObject = getChildAt(0);
            lastChild.x = gutter;
            lastChild.y = gutter;
            for (var i:uint = 1; i < ln; i++) {
                child = getChildAt(i);
                child.x = gutter + lastChild.x + lastChild.width;
                child.y = gutter;
                lastChild = child;
            }
        }

        private function doDrawCircle():void {
            var child:Shape = new Shape();
            var halfSize:uint = Math.round(size / 2);
            child.graphics.beginFill(bgColor);
            child.graphics.lineStyle(borderSize, borderColor);
            child.graphics.drawCircle(halfSize, halfSize, halfSize);
            child.graphics.endFill();
            addChild(child);
        }

        private function doDrawRoundRect():void {
            var child:Shape = new Shape();
            child.graphics.beginFill(bgColor);
            child.graphics.lineStyle(borderSize, borderColor);
            child.graphics.drawRoundRect(0, 0, size, size, cornerRadius);
            child.graphics.endFill();
            addChild(child);
        }

        private function doDrawRect():void {
            var child:Shape = new Shape();
            child.graphics.beginFill(bgColor);
            child.graphics.lineStyle(borderSize, borderColor);
            child.graphics.drawRect(0, 0, size, size);
            child.graphics.endFill();
            addChild(child);
        }
    }
}




[ X ]为什么显示为英语?
《ActionScript 3.0 参考》中的内容以英语显示

《ActionScript 3.0 参考》中的部分内容未翻译成所有语言。当某个语言元素未翻译时,将显示为英语。例如,ga.controls.HelpBox 类未翻译成任何语言。因此在简体中文版的参考中,ga.controls.HelpBox 类显示为英语。