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

PrintJob  - 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.printing
public class PrintJob
继承PrintJob Inheritance EventDispatcher Inheritance Object

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

PrintJob 类用于创建内容并将其打印为一页或多页。此类允许您呈现对用户为可见、动态或在屏幕以外的内容,通过一个“打印”对话框提示用户,以及按照与内容的比例相称的比例打印未缩放的文档。此功能特别适用于呈现和打印动态内容,例如数据库内容和动态文本。

移动浏览器支持:移动浏览器不支持此类。

AIR 配置文件支持:所有桌面操作系统均支持此功能,但移动设备或 AIR for TV 设备不支持此功能。您可以使用 PrintJob.isSupported 属性在运行时测试是否受支持。有关在多个配置文件之间支持 API 的详细信息,请参阅 AIR 配置文件支持

使用 PrintJob() 构造函数创建打印作业。

此外,利用 PrintJob 类的属性,您可以读取用户的打印机设置(如页高度、宽度和图像方向),并且您可以配置文档以动态方式设置适用于打印机设置的 Flash 内容的格式。

注意:与 ActionScript 的先前版本不同,ActionScript 3.0 未将 PrintJob 对象限定在单帧。然而,由于在用户单击“打印”对话框中的“确定”按钮之后,操作系统会向用户显示打印状态信息,所以应尽快调用 PrintJob.addPage()PrintJob.send(),以将页面发送到后台处理程序。如果到达包含 PrintJob.send() 调用的帧时发生延迟,将会延迟打印过程。

另外,以下时间间隔存在 15 秒的脚本超时限制:

  • PrintJob.start() 和第一个 PrintJob.addPage()
  • PrintJob.addPage() 和下一个 PrintJob.addPage()
  • 最后的 PrintJob.addPage()PrintJob.send()

如果以上任何一个间隔时间超过了 15 秒,则对 PrintJob 实例的下一次 PrintJob.start() 调用将返回 false,并且对 PrintJob 实例的下一个 PrintJob.addPage() 将使 Flash Player 或 Adobe AIR 引发运行时异常。

查看示例



公共属性
 属性由以下参数定义
      active : Boolean
[静态] [只读] 表示打印作业当前是否处于活动状态。
PrintJob
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
      copies : int
打印系统打印的、随后将添加到打印作业中的任何页面的备份数。
PrintJob
      firstPage : int
[只读] 用户在操作系统的“打印”对话框中输入的范围内的第一页的页码。
PrintJob
      isColor : Boolean
[只读] 表示当前选择的打印机(采用当前打印设置)使用彩色 (true) 打印还是灰度 (false) 打印。
PrintJob
  isSupported : Boolean
[静态] [只读] 表示当前平台上是否支持 PrintJob 类,支持为 true,不支持为 false。
PrintJob
      jobName : String
打印作业的名称或标题。
PrintJob
      lastPage : int
[只读] 用户在操作系统的“打印”对话框中输入的范围内的最后一页的页码。
PrintJob
      maxPixelsPerInch : Number
[只读] 所选打印机的物理分辨率,以每英寸像素为单位。
PrintJob
  orientation : String
图像的打印方向。
PrintJob
  pageHeight : int
[只读] 可在页面的实际可打印区域中居中放置的最大区域的高度,以点为单位。
PrintJob
  pageWidth : int
[只读] 可在页面的实际可打印区域中居中放置的最大区域的宽度,以点为单位。
PrintJob
      paperArea : Rectangle
[只读] 打印机介质的范围,以点为单位。
PrintJob
  paperHeight : int
[只读] 纸张总高度(以点为单位)。
PrintJob
  paperWidth : int
[只读] 纸张总宽度(以点为单位)。
PrintJob
      printableArea : Rectangle
[只读] 打印机介质的可打印区域的范围,以点为单位。
PrintJob
      printer : String
获取或设置要用于当前打印作业的打印机。
PrintJob
      printers : Vector.<String>
[静态] [只读] 以 String 名称值的形式提供可用打印机的列表。
PrintJob
      supportsPageSetupDialog : Boolean
[静态] [只读] 表示 Flash 运行时环境是否支持单独的“页面设置”对话框。
PrintJob
公共方法
 方法由以下参数定义
  
创建一个可用于打印一页或多页的 PrintJob 对象。
PrintJob
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
  
addPage(sprite:Sprite, printArea:Rectangle = null, options:PrintJobOptions = null, frameNum:int = 0):void
将指定的 Sprite 对象作为单个页面发送到打印后台处理程序。
PrintJob
 Inherited
将事件调度到事件流中。
EventDispatcher
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
表示对象是否已经定义了指定的属性。
Object
 Inherited
表示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
 Inherited
表示指定的属性是否存在、是否可枚举。
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
  
    selectPaperSize(paperSize:String):void
设置页面大小。
PrintJob
  
在成功调用 start() 或 start2() 和 addPage() 方法后,将经过后台处理的页面发送到打印机。
PrintJob
 Inherited
设置循环操作动态属性的可用性。
Object
  
显示操作系统的“页面设置”对话框(如果当前环境支持该对话框)。
PrintJob
  
显示操作系统的“打印”对话框并开始后台处理。
PrintJob
  
    start2(uiOptions:PrintUIOptions = null, showPrintDialog:Boolean = true):Boolean
选择性显示操作系统的“打印”对话框、开始后台处理,并可能修改 PrintJob 只读属性值。
PrintJob
  
    terminate():void
表示打印作业应终止,不发送。
PrintJob
 Inherited
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何祖代为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件 摘要 由以下参数定义
 Inherited[广播事件] Flash Player 或 AIR 应用程序获得操作系统焦点并变为活动状态时将调度此事件。EventDispatcher
 Inherited[广播事件] Flash Player 或 AIR 应用程序失去操作系统焦点并变为非活动状态时将调度此事件。EventDispatcher
属性详细信息
    

active

属性
active:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

表示打印作业当前是否处于活动状态。打印作业在下列任一情况下处于活动状态(属性值是 true):

  • 正在显示“页面设置”或“打印”对话框。
  • 已调用 start()start2() 方法(且返回值是 true),以及未调用 send()terminate() 方法。

如果此属性是 true 并且调用了 showPageSetupDialog()start()start2() 方法,则运行时将引发异常。



实现
    public static function get active():Boolean

相关 API 元素

    

copies

属性 
copies:int

语言版本: ActionScript 3.0
运行时版本: AIR 2

打印系统打印的、随后将添加到打印作业中的任何页面的备份数。此值是用户在操作系统的“打印”对话框中输入的备份数。如果“打印”对话框中没有显示备份数,或者没有向用户显示此对话框,则值为 1(除非应用程序代码对其进行了更改)。



实现
    public function get copies():int
    public function set copies(value:int):void
    

firstPage

属性 
firstPage:int  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

用户在操作系统的“打印”对话框中输入的范围内的第一页的页码。如果用户请求打印所有页面,或如果“打印”对话框中没有显示页面范围,或没有向用户显示“打印”对话框,则该属性为 0。



实现
    public function get firstPage():int
    

isColor

属性 
isColor:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

表示当前选择的打印机(采用当前打印设置)使用彩色 (true) 打印还是灰度 (false) 打印。

如果无法确定彩色或灰度值,则此值为 true



实现
    public function get isColor():Boolean

isSupported

属性 
isSupported:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: Flash Player 10.1, AIR 2

表示当前平台上是否支持 PrintJob 类,支持为 true,不支持为 false



实现
    public static function get isSupported():Boolean
    

jobName

属性 
jobName:String

语言版本: ActionScript 3.0
运行时版本: AIR 2

打印作业的名称或标题。通常,操作系统将作业名称作为打印队列中的作业的标题,或者作为打印到文件中的作业的默认名称。

如果尚未调用 start()start2() 且尚未设置属性的值,则该属性的值为 null

对于您使用 PrintJob 实例执行的各个打印作业,请在调用 start()start2() 方法之前设置此属性。

默认值为 null



实现
    public function get jobName():String
    public function set jobName(value:String):void

引发
IllegalOperationError — 当 active 属性为 true 时,如果代码尝试设置此属性。
    

lastPage

属性 
lastPage:int  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

用户在操作系统的“打印”对话框中输入的范围内的最后一页的页码。如果用户请求打印所有页面,或如果“打印”对话框中没有显示页面范围,或没有向用户显示“打印”对话框,则该属性为 0。



实现
    public function get lastPage():int
    

maxPixelsPerInch

属性 
maxPixelsPerInch:Number  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

所选打印机的物理分辨率,以每英寸像素为单位。根据操作系统报告的当前打印设置计算该值。

如果不能确定分辨率,则该值是标准的默认值。此默认值在 Linux 上为 600 ppi,在 Mac OS 上为 360 ppi。在 Windows 上,打印机分辨率始终可以确定,所以无需使用默认值。



实现
    public function get maxPixelsPerInch():Number

orientation

属性 
orientation:String

语言版本: ActionScript 3.0
运行时版本: Flash Player 9 - read only, AIR 1.0 - read only, AIR 2 - read-write

图像的打印方向。可接受值被定义为 PrintJobOrientation 类中的常量。

注意:对于 AIR 2 或更高版本,请在开始打印作业之前设置此属性,以在“页面设置”和“打印”对话框中设置默认方向。在打印作业正在进行时(调用 start()start2() 后)设置此属性,以设置作业中一系列页面的方向。



实现
    public function get orientation():String
    public function set orientation(value:String):void

相关 API 元素

pageHeight

属性 
pageHeight:int  [只读]

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

可在页面的实际可打印区域中居中放置的最大区域的高度,以点为单位。忽略用户设置的任何边距。仅当调用 PrintJob.start() 方法后,此属性才是可用的。

注意:对于 AIR 2 或更高版本,不推荐使用此属性。请改用 printableArea,此属性测量可打印区域(以小数点为单位)并精确描述中心外的可打印区域。



实现
    public function get pageHeight():int

相关 API 元素

pageWidth

属性 
pageWidth:int  [只读]

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

可在页面的实际可打印区域中居中放置的最大区域的宽度,以点为单位。忽略用户设置的任何边距。仅当调用 PrintJob.start() 方法后,此属性才是可用的。

注意:对于 AIR 2 或更高版本,不推荐使用此属性。请改用 printableArea,此属性测量可打印区域(以小数点为单位)并精确描述中心外的可打印区域。



实现
    public function get pageWidth():int

相关 API 元素

    

paperArea

属性 
paperArea:Rectangle  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

打印机介质的范围,以点为单位。此值使用的坐标系与后续 addPage() 调用使用的坐标系相同。



实现
    public function get paperArea():Rectangle

paperHeight

属性 
paperHeight:int  [只读]

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

纸张总高度(以点为单位)。仅当调用 PrintJob.start() 方法后,此属性才是可用的。

注意:对于 AIR 2 或更高版本,不推荐使用此属性。请改用 paperArea,此属性可测量纸张尺寸(以小数点为单位)。



实现
    public function get paperHeight():int

相关 API 元素

paperWidth

属性 
paperWidth:int  [只读]

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

纸张总宽度(以点为单位)。仅当调用 PrintJob.start() 方法后,此属性才是可用的。

注意:对于 AIR 2 或更高版本,不推荐使用此属性。请改用 paperArea,此属性可测量纸张尺寸(以小数点为单位)。



实现
    public function get paperWidth():int

相关 API 元素

    

printableArea

属性 
printableArea:Rectangle  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

打印机介质的可打印区域的范围,以点为单位。此值使用的坐标系与后续 addPage() 调用使用的坐标系相同。



实现
    public function get printableArea():Rectangle
    

printer

属性 
printer:String

语言版本: ActionScript 3.0
运行时版本: AIR 2

获取或设置要用于当前打印作业的打印机。已传递给 setter 并由 getter 返回的字符串应与由 printers() 方法返回的数组中的其中一个字符串相匹配。要表示应使用默认打印机,请将此值设置为 null。在无法确定默认打印机的操作系统上,此属性的值为 null

     import flash.printing.PrintJob;
     
     var myPrintJob:PrintJob = new PrintJob();
     myPrintJob.printer = "HP_LaserJet_1";
     myPrintJob.start();
     

设置该属性的值会尝试立即选择打印机。如果打印机选择失败,此属性的值将重置为以前的值。您可以确定设置打印机值是否成功,方法如下:在尝试设置此值后读取该值并确认它是否与设置的值一致。

处于活动状态的打印作业的 printer 属性无法更改。在成功调用 start()start2() 方法之后且在调用 send()terminate() 失败之前,尝试更改该值。



实现
    public function get printer():String
    public function set printer(value:String):void
    

printers

属性 
printers:Vector.<String>  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

以 String 名称值的形式提供可用打印机的列表。列表不是预先计算好的,是在调用函数时生成的。如果没有可用的打印机或如果系统不支持打印,则该值为 null。如果系统支持打印但不能返回打印机列表,则该值是一个包含单个元素的矢量(其 length 属性为 1)。在这种情况下,如果不能确定当前打印机名称,则该单个元素将是实际的打印机名称或默认名称。



实现
    public static function get printers():Vector.<String>
    

supportsPageSetupDialog

属性 
supportsPageSetupDialog:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

表示 Flash 运行时环境是否支持单独的“页面设置”对话框。如果该属性为 true,您可以调用 showPageSetupDialog() 方法以显示操作系统的“页面设置”对话框。



实现
    public static function get supportsPageSetupDialog():Boolean

相关 API 元素

构造函数详细信息

PrintJob

()构造函数
public function PrintJob()

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

创建一个可用于打印一页或多页的 PrintJob 对象。在创建一个 PrintJob 对象之后,需要依次使用 PrintJob.start()PrintJob.addPage()PrintJob.send() 方法将打印作业发送到打印机。

例如,可以用自定义参数来替换 myPrintJob.addPage() 方法调用的 [params] 占位符文本,如以下代码中所示:

 // create PrintJob object
 var myPrintJob:PrintJob = new PrintJob();
  
 // display Print dialog box, but only initiate the print job
 // if start returns successfully.
 if (myPrintJob.start()) {
  
    // add specified page to print job
    // repeat once for each page to be printed
    try {
      myPrintJob.addPage([params]);
    }
    catch(e:Error) {
      // handle error 
    }
    try {
      myPrintJob.addPage([params]);
    }
    catch(e:Error) {
      // handle error 
    }
 
    // send pages from the spooler to the printer, but only if one or more
    // calls to addPage() was successful. You should always check for successful 
    // calls to start() and addPage() before calling send().
    myPrintJob.send();
 }
 

在 AIR 2 或更高版本中,您可以创建并使用多个 PrintJob 实例。打印完成后,对 PrintJob 实例设置的属性仍保留。这就允许您重用 PrintJob 实例并维持用户选择的打印首选项,同时还为应用程序中的其他内容提供不同的打印首选项。对于 Flash Player 和 AIR 版本 2 之前的版本中的内容,当某个 PrintJob 对象仍处于活动状态时,您无法再创建一个 PrintJob 对象。如果在第一个 PrintJob 对象仍处于活动状态时创建第二个 PrintJob 对象(通过调用 new PrintJob()),则第二个 PrintJob 对象不会被创建。因此,在创建其他 PrintJob 之前,您可以查看 myPrintJob 值。


引发
IllegalOperationError — 在 Flash Player 和 AIR 2 之前的 AIR 中,如果其他 PrintJob 对象仍处于活动状态,将引发异常。

相关 API 元素

方法详细信息

addPage

()方法
public function addPage(sprite:Sprite, printArea:Rectangle = null, options:PrintJobOptions = null, frameNum:int = 0):void

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

将指定的 Sprite 对象作为单个页面发送到打印后台处理程序。在使用此方法之前,必须创建 PrintJob 对象,然后使用 start()start2()。然后,在针对某个打印作业一次或多次调用 addPage() 后,请使用 send() 将经过后台处理的页发送到打印机。换言之,在创建 PrintJob 对象后,请使用(按照以下顺序)start()start2()addPage()send() 将打印作业发送到打印机。在打印作业中,在调用 start() 一次后,您可以多次调用 addPage() 以打印多个页面。

如果 addPage() 导致 Flash Player 引发异常(例如,如果您尚未调用 start() 或用户取消了打印作业),对 addPage() 的任何后续调用都会失败。但是,如果之前对 addPage() 的调用成功,则最后的 send() 命令将经后台成功处理的页发送到打印机。

如果打印作业用 15 秒以上的时间完成一次 addPage() 操作,则 Flash Player 在下一次调用 addPage() 时将引发异常。

如果为 printArea 参数传递了值,则 printArea Rectangle 的 xy 坐标将映射到页上可打印区域的左上角(0, 0 坐标)。只读属性 pageHeightpageWidth 规定了由 start() 设置的可打印区域。因为打印输出与页面上可打印区域的左上角对齐,所以如果在 printArea 中定义的区域大于页面上的可打印区域,则打印输出会在由 printArea 定义的区域的右边和/或底部被截断。在 Flash Professional 中,如果没有为 printArea 传递值并且 Stage 大于可打印区域,则将发生此类型的剪裁。在 Flex 或 Flash Builder 中,如果没有为 printArea 传递值并且屏幕大于可打印区域,则将发生此类型的剪裁。

如果要在打印前对 Sprite 对象进行缩放,则可在调用此方法之前设置缩放属性(参见 flash.display.DisplayObject.scaleXflash.display.DisplayObject.scaleY),并在打印之后将它们重新设置为原始值。Sprite 对象的缩放与 printArea 无关。也就是说,如果指定一个 50 x 50 像素的打印区域,则会打印 2500 像素。如果对 Sprite 对象进行缩放,则同样会打印 2500 像素,但是将按缩放后的大小打印 Sprite 对象。

Flash Player 打印功能支持 PostScript 和非 PostScript 打印机。非 PostScript 打印机将矢量转换成位图。

参数

sprite:Sprite — 包含要打印内容的 Sprite。
 
printArea:Rectangle (default = null) — 指定要打印的区域的 Rectangle 对象。

矩形的宽度和高度以像素为单位。打印机使用点来作为打印的度量单位。点的实际大小是固定的(1/72 英寸),但是在屏幕上,像素的大小取决于特定屏幕的分辨率。因此,像素和点之间的转换比率取决于打印机设置以及 sprite 是否经过缩放。一个 72 像素宽的 Sprite 在未经缩放的情况下打印输出为一英寸宽,这时,一点等于一像素,与屏幕分辨率无关。

您可以使用以下换算公式将英寸或厘米转换为缇或点(1 缇为 1/20 点):

  • 一点 = 1/72 英寸 = 20 缇
  • 1 英寸 = 72 点 = 1440 缇
  • 1 厘米 = 567 缇

如果省略了 printArea 参数或错误地传递了该参数,将打印 sprite 参数的整个区域。

如果您不希望指定 printArea 的值,而是希望指定 optionsframeNum 的值,请为 printArea 传递 null

 
options:PrintJobOptions (default = null) — 一个可选参数,指定是作为矢量打印还是作为位图打印。默认值为 null,表示请求矢量打印。要将 sprite 作为位图打印,请将 PrintJobOptions 对象的 printAsBitmap 属性设置为 true。当确定是否将 printAsBitmap 设置为 true 时,请记住以下建议:
  • 如果您打印的内容包括位图图像,请将 printAsBitmap 设置为 true 以包括任何 Alpha 透明度和色彩效果。
  • 如果内容不包含位图图像,则请省略此参数,以便以较高品质的矢量格式打印内容。

如果省略或错误传递了 options,则使用矢量打印。如果您不希望指定 options 的值,而是希望指定 frameNumber 的值,请为 options 传递 null

 
frameNum:int (default = 0) — 一个可选数字,用于指定要打印的 MovieClip 对象的帧。传递 frameNum 不会调用此帧上的 ActionScript。如果省略此参数并且 sprite 参数是 MovieClip 对象,则打印 sprite 中的当前帧。


引发
Error — 如果您尚未调用 start() 或用户取消了打印作业,将引发异常

相关 API 元素

    selectPaperSize

()方法 
public function selectPaperSize(paperSize:String):void

语言版本: ActionScript 3.0
运行时版本: AIR 2

设置页面大小。paperSize 参数可接受的值是 PaperSize 类中的常量。调用此方法将影响打印设置,如同用户在“页面设置”或“打印”对话框中选择页面大小。

您可以随时调用此方法。在开始打印作业之前调用此方法,以在“页面设置”和“打印”对话框中设置默认页面大小。在打印作业过程中调用此方法,以设置此作业中一系列页面的页面大小。

     import flash.printing.PrintJob;
     import flash.printing.PaperSize;
     
     var myPrintJob:PrintJob = new PrintJob();
     myPrintJob.selectPaperSize(PaperSize.ENV_10);
     

参数

paperSize:String — 在打印作业中用于后续页的页面大小


引发
ArgumentError — 如果 paperSize 参数不属于在 PaperSize 类中定义的可接受值。

相关 API 元素

send

()方法 
public function send():void

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

在成功调用 start()start2()addPage() 方法后,将经过后台处理的页面发送到打印机。

如果调用 start()start2() 方法失败,或者如果调用 addPage() 方法时引发异常,则该方法不会成功。要避免发生错误,在调用此方法之前,请核实 start()start2() 方法返回 true 并捕获任何 addPage() 异常。以下示例演示了如何在调用此方法之前正确检查错误:

     var myPrintJob:PrintJob = new PrintJob();
     if (myPrintJob.start()) {
       try {
         myPrintJob.addPage([params]);
       }
       catch(e:Error) {
          // handle error 
       }
     
       myPrintJob.send();
     }
     

相关 API 元素

    showPageSetupDialog

()方法 
public function showPageSetupDialog():Boolean

语言版本: ActionScript 3.0
运行时版本: AIR 2

显示操作系统的“页面设置”对话框(如果当前环境支持该对话框)。使用 supportsPageSetupDialog 属性确定是否支持“页面设置”。

     import flash.printing.PrintJob;
     
     var myPrintJob:PrintJob = new PrintJob();
     if (myPrintJob.supportsPageSetupDialog)
     {
         myPrintJob.showPageSetupDialog();
     }
     

返回
Boolean — 如果用户在“页面设置”对话框中选择“确定”,则为 true。这表明某些 PrintJob 属性可能已更改。如果用户在“页面设置”对话框中选择“取消”,则返回 false

引发
IllegalOperationError — 如果此系统不支持“页面设置”。使用 supportsPageSetupDialog 属性确定是否支持“页面设置”。
 
IllegalOperationError — 如果任何打印作业(包括当前作业)处于活动状态。

相关 API 元素

start

()方法 
public function start():Boolean

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

显示操作系统的“打印”对话框并开始后台处理。通过“打印”对话框,用户可更改打印设置。当 PrintJob.start() 方法成功返回时(用户单击“打印”对话框中的“确定”),将填充下列属性,从而显示用户选择的打印设置:

属性类型单位注释
PrintJob.paperHeightNumber纸张整体高度。
PrintJob.paperWidthNumber纸张整体宽度。
PrintJob.pageHeightNumber页上实际可打印区域的高度;忽略用户设置的任何边距。
PrintJob.pageWidthNumber页上实际可打印区域的宽度;忽略用户设置的任何边距。
PrintJob.orientation字符串"portrait" (flash.printing.PrintJobOrientation.PORTRAIT) 或 "landscape" (flash.printing.PrintJobOrientation.LANDSCAPE)。

注意:如果用户取消“打印”对话框,则不会填充属性。

当用户在“打印”对话框中单击“确定”之后,播放器开始在后台将打印作业处理到操作系统。因为操作系统随后开始向用户显示有关打印过程的信息,所以应尽快调用 PrintJob.addPage()PrintJob.send() 调用,以将页发送到后台处理程序。您可以使用此方法的只读 height、width 和 orientation 属性进行填充以设置打印输出格式。

进行测试,以查看此方法是否返回 true(当用户在操作系统的“打印”对话框中单击“确定”时),这应在对 PrintJob.addPage()PrintJob.send() 执行任何后续调用之前进行:

     var myPrintJob:PrintJob = new PrintJob();
        if(myPrintJob.start()) {
          // addPage() and send() statements here
        }
     

对给定的打印作业实例而言,如果以下任何一个间隔的持续时间超过 15 秒,则对 PrintJob.start() 的下一次调用将返回 false

  • PrintJob.start() 和第一个 PrintJob.addPage()
  • 一个 PrintJob.addPage() 和下一个 PrintJob.addPage()
  • 最后的 PrintJob.addPage()PrintJob.send()

返回
Boolean — 如果显示“打印”对话框时用户单击“确定”,则返回 true;如果用户单击“取消”或出现错误,则返回 false

引发
IllegalOperationError — 在 AIR 2 或更高版本中,如果其他 PrintJob 当前处于活动状态

相关 API 元素

    start2

()方法 
public function start2(uiOptions:PrintUIOptions = null, showPrintDialog:Boolean = true):Boolean

语言版本: ActionScript 3.0
运行时版本: AIR 2

选择性显示操作系统的“打印”对话框、开始后台处理,并可能修改 PrintJob 只读属性值。

uiOptions 参数允许调用方控制在“打印”对话框中显示哪些选项。请参见 PrintUIOptions 类。如果 showPrintDialog 为 false,则忽略此参数。

即使当 showPrintDialogtrue 时,此方法的行为也可能与 start() 方法不同。在某些操作系统上,start() 在显示“页面设置”对话框后显示“打印”对话框。相反,start2() 从不显示“页面设置”对话框。

在下面的示例中,在向用户显示“打印”对话框之前,需要对其中的最小和最大页面设置进行设置:

     import flash.printing.PrintJob;
     import flash.printing.PrintUIOptions;
     
     var myPrintJob:PrintJob = new PrintJob();
     var uiOpt:PrintUIOptions = new PrintUIOptions();
     uiOpt.minPage = 1;
     uiOpt.maxPage = 3;
     var accepted:Boolean = myPrintJob.start2(uiOpt);
     

参数

uiOptions:PrintUIOptions (default = null) — 一个对象,指定在向用户显示的“打印”对话框中显示的选项。如果 showPrintDialog 参数是 false,则忽略此值。
 
showPrintDialog:Boolean (default = true) — 在开始打印作业之前是否向用户显示“打印”对话框

返回
Boolean — 如果用户在“打印”对话框出现时单击“确定”,或者未显示“打印”对话框而且未发生错误,则值为 true;如果用户单击“取消”或有错误发生,值为 false

引发
IllegalOperationError — 如果正在显示“页面设置”对话框,或者如果其他打印作业当前处于活动状态

相关 API 元素

    terminate

()方法 
public function terminate():void

语言版本: ActionScript 3.0
运行时版本: AIR 2

表示打印作业应终止,不发送。当打印作业已通过调用 start()start2() 启动,但不适合将任何页面发送到打印机时,请使用此方法。通常,terminate() 仅用于从错误恢复。

在调用此方法后,PrintJob 实例可以重用。尽可能保留作业的打印设置以供后续使用。

PrintJobExample_Simple.as

以下示例显示打印的基本过程。新建了一个 PrintJob,如果已成功开始,addPage() 方法会将该 sprite 作为单个页添加。send() 方法将该页后台打印到打印机。
package 
{ 
    import flash.printing.PrintJob; 
    import flash.display.Sprite; 
 
    public class BasicPrintExample extends Sprite 
    { 
        var myPrintJob:PrintJob = new PrintJob(); 
        var mySprite:Sprite = new Sprite();
        mySprite.graphics.beginFill(0x336699);
    mySprite.graphics.drawCircle(100, 100, 50);
 
        public function BasicPrintExample() 
        { 
            if (myPrintJob.start()) {
            try {
                myPrintJob.addPage(mySprite);
            }
            catch(e:Error) {
                // handle error 
            }
            myPrintJob.send();
        } 
    } 
}
PrintJobExample.as

以下示例使用类 PrintJobExample 来创建一个小文档,然后将该文档发送到打印机。这是使用以下步骤完成的:
  1. 声明两个 Sprite 类型的变量,名称为 sheet1sheet2
  2. 调用 init(),它将一个新的 Sprite 实例同时赋给 sheet1sheet2,然后使用不同的参数调用 createSheet()
  3. createSheet() 进行以下操作:
    1. 传入的 Sprite 对象用来在 x = 0、y = 0 处绘制一个矩形,矩形具有浅灰色背景和一个像素宽的黑色边框,宽度为 100 像素,高度为 200 像素。
    2. 创建一个新的 TextField 对象,名为 txt,尺寸和 Sprite 相同,wordWrap 属性设置为 true,并且 text 属性设置为作为参数传递给 createSheet() 的 String。
    3. 如果传递的 Object 参数不是 null,则创建一个新的 Sprite 实例,名为 img,该实例使用所传递的 Object 的坐标和尺寸属性绘制一个白色矩形。可将白色矩形添加到 Sprite 对象的显示列表中,方法是使用 addChild()
    4. 可将 txt TextField 添加到 Sprite 对象的显示列表中,方法是使用 addChild()
  4. 回到构造函数中,调用已启用的(不是被注释掉的)打印方法 由于方法非常相似,因此下面将描述 printOnePerPage()
  5. printOnePerPage() 进行以下操作:
    1. 声明一个新的 PrintJob 对象,名称为 pj,并将 pagesToPrint 声明为 unit 类型。
    2. 打开操作系统的本机打印对话框,并等待用户单击 OK
    3. 检查方向,如果选择了横向,则将引发错误并退出。
    4. 设置 sheet1sheet2 的页面高度和宽度。
    5. 使用 addPage()sheet1sheet2 发送到打印后台处理程序。
    6. 如果要打印的页数 > 0,则打印所有经过后台处理的页。
  6. 调用 draw() 方法,它调整两个 Sprite 属性的大小以适合舞台大小,并重新定位 sheet2,以便它紧挨着 sheet1 的右侧。

注意:设置构造函数后,可以根据首选项选择三种打印方法中的一种(每页一张,每页两张,或是在页面的上半部分打印)。如果不使用代码注释禁用其中的两种打印方法,则此示例将不能正确运行 示例经过设置,以调用 printOnePerPage()

package {
    import flash.printing.PrintJob;
    import flash.printing.PrintJobOrientation;
    import flash.display.Stage;
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.geom.Rectangle;
       
    public class PrintJobExample extends Sprite {
        private var sheet1:Sprite;
        private var sheet2:Sprite;
           
        public function PrintJobExample() {
            init();
            printOnePerPage();
//            printTwoPerPage();
//            printTopHalf();
            draw();
        }
        
        private function init():void {
            sheet1 = new Sprite();
            createSheet(sheet1, "Once upon a time...", {x:10, y:50, width:80, height:130});

            sheet2 = new Sprite();
            createSheet(sheet2, "There was a great story to tell, and it ended quickly.\n\nThe end.", null);
        }
        
        private function createSheet(sheet:Sprite, str:String, imgValue:Object):void {
            sheet.graphics.beginFill(0xEEEEEE);
            sheet.graphics.lineStyle(1, 0x000000);
            sheet.graphics.drawRect(0, 0, 100, 200);
            sheet.graphics.endFill();
            
            var txt:TextField = new TextField();
            txt.height = 200;
            txt.width = 100;
            txt.wordWrap = true;
            txt.text = str;
            
            if(imgValue != null) {
                var img:Sprite = new Sprite();
                img.graphics.beginFill(0xFFFFFF);
                img.graphics.drawRect(imgValue.x, imgValue.y, imgValue.width, imgValue.height);
                img.graphics.endFill();
                sheet.addChild(img);
            }
            sheet.addChild(txt);
        }
        
        private function printOnePerPage():void {
            var pj:PrintJob = new PrintJob();
            var pagesToPrint:uint = 0;
            if(pj.start()) {                
                if(pj.orientation == PrintJobOrientation.LANDSCAPE) {    
                    throw new Error("Without embedding fonts you must print one sheet per page with an orientation of portrait.");
                }
                
                sheet1.height = pj.pageHeight;
                sheet1.width = pj.pageWidth;
                sheet2.height = pj.pageHeight;
                sheet2.width = pj.pageWidth;

                try {
                    pj.addPage(sheet1);
                    pagesToPrint++;
                }
                catch(e:Error) {
                    // do nothing
                }

                try {
                    pj.addPage(sheet2);
                    pagesToPrint++;
                }
                catch(e:Error) {
                    // do nothing
                }

                if(pagesToPrint > 0) {
                    pj.send();
                }
            }
        }
        
        private function printTwoPerPage():void {
            var pj:PrintJob = new PrintJob();
            var pagesToPrint:uint = 0;
            if(pj.start()) {                
                if(pj.orientation == PrintJobOrientation.PORTRAIT) {
                    throw new Error("Without embedding fonts you must print two sheets per page with an orientation of landscape.");
                }
                
                sheet1.height = pj.pageHeight;
                sheet1.width = pj.pageWidth/2;
                sheet2.height = pj.pageHeight;
                sheet2.width = pj.pageWidth/2;

                var sheets:Sprite = new Sprite();
                sheets.addChild(sheet1);
                sheets.addChild(sheet2);
                sheets.getChildAt(1).x = sheets.getChildAt(0).width;
                try {
                    pj.addPage(sheets);
                    pagesToPrint++;
                }
                catch(e:Error) {
                    // do nothing
                }

                if(pagesToPrint > 0) {
                    pj.send();
                }
            }
        }

        private function printTopHalf():void {
            var pj:PrintJob = new PrintJob();
            var pagesToPrint:uint = 0;
            if(pj.start()) {                
                if(pj.orientation == PrintJobOrientation.PORTRAIT) {
                    throw new Error("Without embedding fonts you must print the top half with an orientation of landscape.");
                }
                
                sheet1.height = pj.pageHeight;
                sheet1.width = pj.pageWidth/2;
                sheet2.height = pj.pageHeight;
                sheet2.width = pj.pageWidth/2;

                var sheets:Sprite = new Sprite();
                sheets.addChild(sheet1);
                sheets.addChild(sheet2);
                sheets.getChildAt(1).x = sheets.getChildAt(0).width;
                try {
                    pj.addPage(sheets, new Rectangle(0, 0, sheets.width, sheets.height/2));
                    pagesToPrint++;
                }
                catch(e:Error) {
                    // do nothing
                }

                if(pagesToPrint > 0) {
                    pj.send();
                }
            }
        }


        private function draw():void {
            var sheetWidth:Number = this.stage.stageWidth/2;
            var sheetHeight:Number = this.stage.stageHeight;
            
            addChild(sheet1);
            sheet1.width = sheetWidth;
            sheet1.height = sheetHeight;
            
            addChild(sheet2);
            sheet2.width = sheetWidth;
            sheet2.height = sheetHeight;
            sheet2.x = sheet1.width;
        }        
    }
}
PrintJobExample.2.as

以下示例显示了一些其他的打印功能。本示例提供了有关打印份数、纸张大小 (legal) 和页面方向(横向)的初始化 PrintJob 设置。它会强制首先显示“页面设置”对话框,然后通过显示“打印”对话框来启动打印作业。
 
package 
 { 
     import flash.display.Sprite; 
     import flash.display.Stage; 
     import flash.geom.Rectangle; 
     import flash.printing.PaperSize; 
     import flash.printing.PrintJob; 
    import flash.printing.PrintJobOrientation; 
    import flash.printing.PrintUIOptions; 
    import flash.text.TextField; 
      
     public class PrintJobExample extends Sprite 
     { 
         private var bg:Sprite; 
         private var txt:TextField; 
        private var pj:PrintJob; 
        private var uiOpt:PrintUIOptions; 
  
         public function PrintJobExample():void 
         { 
            var pj = new PrintJob(); 
            uiOpt = new PrintUIOptions(); 
            initPrintJob(); 
             initContent(); 
             draw(); 
             printPage(); 
         } 
          
         private function printPage():void 
         { 
            if (pj.supportsPageSetupDialog) 
            { 
                pj.showPageSetupDialog(); 
            }
            
             if (pj.start2(uiOpt, true)) 
             { 
                   try 
                 { 
                     pj.addPage(this, new Rectangle(0, 0, 100, 100)); 
                 } 
                 catch (error:Error) 
                 { 
                     // Do nothing. 
                 } 
                 pj.send(); 
             } 
             else 
             { 
                 txt.text = "Print job terminated"; 
                pj.terminate(); 
             } 
         } 
         
         private function initContent():void 
         { 
             bg = new Sprite(); 
             bg.graphics.beginFill(0x00FF00); 
             bg.graphics.drawRect(0, 0, 100, 200); 
             bg.graphics.endFill(); 
              
             txt = new TextField(); 
             txt.border = true; 
             txt.text = "Hello World"; 
         } 
          
        private function initPrintJob():void 
        { 
            pj.setPaperSize(PaperSize.LEGAL); 
            pj.orientation = PrintJobOrientation.LANDSCAPE; 
            pj.copies = 2; 
            pj.jobName = "Flash test print";
        } 
         
         private function draw():void 
         { 
             addChild(bg); 
             addChild(txt); 
             txt.x = 50; 
             txt.y = 50; 
         } 
     } 
}




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

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