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

FileReference  - 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.net
public class FileReference
继承FileReference Inheritance EventDispatcher Inheritance Object
子类 File

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

FileReference 类提供了在用户计算机和服务器之间上载和下载文件的方法。操作系统对话框会提示用户选择要上载的文件或用于下载的位置。每个 FileReference 对象都引用用户磁盘上的一个文件并且具有一些属性,这些属性包含有关文件大小、类型、名称、创建日期、修改日期和创建者类型(仅限 Macintosh)的信息。

注意:在 Adobe AIR 中,File 类(用于扩展 FileReference 类)提供了更多的功能,并具有比 FileReference 类更少的安全性限制。

FileReference 实例的创建方式如下:

  • 当将 new 运算符与 FileReference 构造函数一起使用时:var myFileReference = new FileReference();
  • 当调用 FileReferenceList.browse() 方法时,该方法将创建一个 FileReference 对象数组。

在上载操作期间,FileReference 对象的所有属性通过调用 FileReference.browse()FileReferenceList.browse() 方法来填充。在下载操作期间,name 属性在调度 select 事件时得到填充,所有其他属性在调度 complete 事件时得到填充。

browse() 方法打开一个操作系统对话框,提示用户选择要上载的文件。FileReference.browse() 方法允许用户选择一个文件;FileReferenceList.browse() 方法允许用户选择多个文件。成功调用 browse() 方法后,调用 FileReference.upload() 方法以每次上载一个文件。FileReference.download() 方法提示用户提供文件的保存位置并开始从远程 URL 进行下载。

FileReference 类和 FileReferenceList 类不允许为 browse()download() 生成的对话框设置默认文件位置。对话框中显示的默认位置是最近浏览过的文件夹(如果可以确定该位置)或桌面。这些类不允许对已传输的文件进行读取或写入。它们也不允许启动上载或下载的 SWF 文件访问已上载或下载的文件或用户磁盘上文件的位置。

FileReference 类和 FileReferenceList 类也不提供用于身份验证的方法。通过要求身份验证的服务器,您可以使用 Flash ® Player 浏览器插件下载文件,但上载(在所有播放器上)和下载(在独立播放器或外部播放器上)将失败。对 FileReference 事件进行侦听可确定操作是否成功完成,并进行错误处理。

对于在 Flash Player 中运行的内容或在 Adobe AIR 中的应用程序安全沙箱以外的区域运行的内容,上载和下载操作只能访问所在域和 URL 策略文件指定的任何域中的文件。如果启动上载或下载的内容与文件服务器不在相同的域中,则需要将策略文件放到文件服务器上。

请注意,由于已向 Flash Player 中添加了新功能,因此当发布到 Flash Player 10 时,一次只可以激活下列操作中的一个操作:FileReference.browse()FileReference.upload()FileReference.download()FileReference.load()FileReference.save()。否则,Flash Player 会引发运行时错误(代码 2174)。使用 FileReference.cancel() 可停止正在进行的操作。此限制仅适用于 Flash Player 10。早期版本的 Flash Player 在同时进行多个操作时不会受到此限制的影响。

调用 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法的过程中,对于 Linux 和 Mac OS X 10.1 及早期版本,将暂停 Flash Player 的独立和外部版本中以及 AIR 中的 SWF 文件播放

如果未指定任何参数,则 Flash Player 会向服务器端脚本发送以下范例 HTTP POST 请求:

  POST /handler.cfm HTTP/1.1 
  Accept: text/*
  Content-Type: multipart/form-data; 
  boundary=----------Ij5ae0ae0KM7GI3KM7 
  User-Agent: Shockwave Flash 
  Host: www.example.com 
  Content-Length: 421 
  Connection: Keep-Alive 
  Cache-Control: no-cache
  
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="Filename"
  
  MyFile.jpg
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="Filedata"; filename="MyFile.jpg"
  Content-Type: application/octet-stream
  
  FileDataHere
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="Upload"
  
  Submit Query
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7--
  

如果用户指定参数 "api_sig""api_key""auth_token",Flash Player 将发送以下 HTTP POST 请求:

  POST /handler.cfm HTTP/1.1 
  Accept: text/*
  Content-Type: multipart/form-data; 
  boundary=----------Ij5ae0ae0KM7GI3KM7 
  User-Agent: Shockwave Flash 
  Host: www.example.com 
  Content-Length: 421 
  Connection: Keep-Alive 
  Cache-Control: no-cache
  
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="Filename"
  
  MyFile.jpg
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="api_sig"
  
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="api_key"
  
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="auth_token"
  
  XXXXXXXXXXXXXXXXXXXXXX
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="Filedata"; filename="MyFile.jpg"
  Content-Type: application/octet-stream
  
  FileDataHere
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
  Content-Disposition: form-data; name="Upload"
  
  Submit Query
  ------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7--
  

查看示例

相关 API 元素



公共属性
 属性由以下参数定义
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
  creationDate : Date
[只读] 本地磁盘上文件的创建日期。
FileReference
  creator : String
[只读] 文件的 Macintosh 创建者类型,此类型仅用于 Mac OS X 之前的 Mac OS 版本中。
FileReference
  data : ByteArray
[只读] 成功调用 load() 方法之后代表所加载文件中的数据的 ByteArray 对象。
FileReference
      extension : String
[只读] 文件扩展名。
FileReference
  modificationDate : Date
[只读] 本地磁盘上文件的上一次修改日期。
FileReference
  name : String
[只读] 本地磁盘上的文件的名称。
FileReference
      permissionStatus : String
[静态] [只读] 确定应用程序是否已被授予文件系统访问权限。
FileReference
  size : Number
[只读] 本地磁盘上文件的大小(以字节为单位)。
FileReference
  type : String
[只读] 文件类型。
FileReference
公共方法
 方法由以下参数定义
  
创建新的 FileReference 对象。
FileReference
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
  
browse(typeFilter:Array = null):Boolean
显示一个文件浏览对话框,让用户选择要上载的文件。
FileReference
  
取消正在对该 FileReference 对象执行的任何上载或下载操作。
FileReference
 Inherited
将事件调度到事件流中。
EventDispatcher
  
download(request:URLRequest, defaultFileName:String = null):void
打开对话框,以允许用户从远程服务器下载文件。
FileReference
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
表示对象是否已经定义了指定的属性。
Object
 Inherited
表示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
  
开始加载用户选择的本地文件。
FileReference
 Inherited
表示指定的属性是否存在、是否可枚举。
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
  
申请文件系统访问权限
FileReference
  
save(data:*, defaultFileName:String = null):void
打开一个对话框,允许用户将文件保存到本地文件系统。
FileReference
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
  
upload(request:URLRequest, uploadDataFieldName:String = "Filedata", testUpload:Boolean = false):void
开始将文件上载到远程服务器。
FileReference
  
启动将文件上载到 URL 的操作,不进行任何编码。
FileReference
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何祖代为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件 摘要 由以下参数定义
 Inherited[广播事件] Flash Player 或 AIR 应用程序获得操作系统焦点并变为活动状态时将调度此事件。EventDispatcher
  当用户通过文件浏览对话框取消文件上载或下载时调度。FileReference
  当下载操作完成或上载操作生成 HTTP 状态代码 200 时调度。FileReference
 Inherited[广播事件] Flash Player 或 AIR 应用程序失去操作系统焦点并变为非活动状态时将调度此事件。EventDispatcher
  在 upload() 或 uploadUnencoded() 方法调用尝试通过 HTTP 访问数据,并且 Adobe AIR 可以检测并返回请求的状态代码时调度。FileReference
  当上载失败并且存在可用来描述失败的 HTTP 状态代码时调度。FileReference
  当上载或下载失败时调度。FileReference
  当上载或下载操作开始时调度。FileReference
  当应用程序申请文件系统访问权限时调度。FileReference
  在文件上载或下载操作期间定期调度。FileReference
  当对 FileReference.upload() 或 FileReference.download() 方法的调用尝试将文件上载到调用方安全沙箱外部的服务器,或是从调用方安全沙箱外部的服务器上下载文件时进行调度。FileReference
  当用户从文件浏览对话框选择要上载或下载的文件时调度。FileReference
  成功上载并从服务器接收数据之后调度。FileReference
属性详细信息

creationDate

属性
creationDate:Date  [只读]

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

本地磁盘上文件的创建日期。如果未填充对象,则为获取此属性的值而执行的调用将返回 null

注意:如果操作系统未将 creationDate 作为其属性,在这些情况下,CreationDate 等于 lastModifiedDate



实现
    public function get creationDate():Date

引发
IllegalOperationError — 若 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法未能成功调用,将引发异常,同时显示一条信息,指出函数的调用顺序不正确或先前调用未成功。此时,creationDate 属性的值为 null
 
IOError — 若不能访问文件信息,则会引发一个异常,同时显示一条信息,指出发生文件 I/O 错误。

相关 API 元素

creator

属性 
creator:String  [只读]

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

文件的 Macintosh 创建者类型,此类型仅用于 Mac OS X 之前的 Mac OS 版本中。在 Windows 或 Linux 中,此属性为 null。如果未填充 FileReference 对象,则为获得此属性的值而执行的调用将返回 null



实现
    public function get creator():String

引发
IllegalOperationError — 在 Macintosh 系统上,若 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法未能成功调用,将引发异常,同时显示一条信息,指出函数的调用顺序不正确或先前调用未成功。此时,creator 属性的值为 null

相关 API 元素

data

属性 
data:ByteArray  [只读]

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

成功调用 load() 方法之后代表所加载文件中的数据的 ByteArray 对象。



实现
    public function get data():ByteArray

引发
IllegalOperationError — 如果 load() 方法未能成功调用,则将引发异常,同时显示一条消息,表示函数的调用顺序不正确或先前调用未成功。在这种情况下,data 属性的值为 null
 
IOError — 若无法打开或读取文件,或者在访问文件时遇到类似错误,将引发异常,同时显示一条信息,指明发生文件 I/O 错误。在这种情况下,data 属性的值为 null

相关 API 元素

    

extension

属性 
extension:String  [只读]

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

文件扩展名。

文件的扩展名是最后一个句点(“.”)后面的名称部分(不包括句点)。如果文件名中没有句点,则 extension 为 null

注意:应该使用 extension 属性来确定文件的类型,不要使用 creatortype 属性。应该将 creatortype 属性视为已不推荐使用。它们适用于 Mac OS 的早期版本。



实现
    public function get extension():String

引发
IllegalOperationError — 如果未初始化引用。

modificationDate

属性 
modificationDate:Date  [只读]

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

本地磁盘上文件的上一次修改日期。如果未填充 FileReference 对象,则为获得此属性的值而执行的调用将返回 null



实现
    public function get modificationDate():Date

引发
IllegalOperationError — 若 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法未能成功调用,将引发异常,同时显示一条信息,指出函数的调用顺序不正确或先前调用未成功。此时,modificationDate 属性的值为 null
 
IOError — 若不能访问文件信息,则会引发一个异常,同时显示一条信息,指出发生文件 I/O 错误。

相关 API 元素

name

属性 
name:String  [只读]

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

本地磁盘上的文件的名称。如果未填充 FileReference 对象(通过对 FileReference.download()FileReference.browse() 的有效调用),则在尝试获取此属性的值时,Flash Player 将引发错误。

FileReference 对象的所有属性都通过调用 browse() 方法进行填充。与其他 FileReference 属性不同,如果调用 download() 方法,则在调度 select 事件时将填充 name 属性。



实现
    public function get name():String

引发
IllegalOperationError — 若 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法未能成功调用,将引发异常,同时显示一条信息,指出函数的调用顺序不正确或先前调用未成功。

相关 API 元素

    

permissionStatus

属性 
permissionStatus:String  [只读]

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

确定应用程序是否已被授予文件系统访问权限。



实现
    public static function get permissionStatus():String

相关 API 元素

size

属性 
size:Number  [只读]

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

本地磁盘上文件的大小(以字节为单位)。

注意:在 ActionScript 3.0 的初始版本中,size 属性定义为 uint 对象,该对象支持大小达 4 GB 的文件。现在,它以 Number 对象的形式实现,以支持更大的文件。



实现
    public function get size():Number

引发
IllegalOperationError — 若 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法未能成功调用,将引发异常,同时显示一条信息,指出函数的调用顺序不正确或先前调用未成功。
 
IOError — 若无法打开或读取文件,或者在访问文件时遇到类似错误,将引发异常,同时显示一条信息,指明发生文件 I/O 错误。

相关 API 元素

type

属性 
type:String  [只读]

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

文件类型。

在 Windows 或 Linux 上,此属性是文件扩展名。在 Macintosh 上,此属性是由四个字符组成的文件类型,仅用于 Mac OS X 之前的 Mac OS 版本中。如果未填充 FileReference 对象,则为获取此属性的值而执行的调用将返回 null

对于 Windows、Linux 和 Mac OS X,文件扩展名 — name 属性最后一个句点 (.) 字符后的部分character — 标识文件类型。



实现
    public function get type():String

引发
IllegalOperationError — 若 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法未能成功调用,将引发异常,同时显示一条信息,指出函数的调用顺序不正确或先前调用未成功。此时,type 属性的值为 null

相关 API 元素

构造函数详细信息

FileReference

()构造函数
public function FileReference()

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

创建新的 FileReference 对象。在填充后,FileReference 对象表示用户本地磁盘上的文件。

相关 API 元素

方法详细信息

browse

()方法
public function browse(typeFilter:Array = null):Boolean

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

显示一个文件浏览对话框,让用户选择要上载的文件。该对话框对于用户的操作系统来说是本机的。用户可以选择本地计算机上的文件,也可以选择其他系统上的文件,例如,通过 Windows 上的 UNC 路径选择文件。

注意:可在 Adobe AIR 中使用的 File 类包括用于访问更具体的系统文件选择对话框的方法。这些方法是 File.browseForDirectory()File.browseForOpen()File.browseForOpenMultiple()File.browseForSave()

当调用此方法并且用户成功选择文件时,会使用该文件的属性填充此 FileReference 对象的属性。以后每次调用 FileReference.browse() 方法时,FileReference 对象的属性都重置为用户在对话框中选择的文件。每次只能执行一个 browse()download() 会话(因为每次只能调用一个对话框)。

使用 typeFilter 参数,可决定对话框显示哪些文件。

在 Flash Player 10 和 Flash Player 9 Update 5 中,只有响应用户事件(例如,在鼠标单击或按键事件的事件处理函数中)才能成功调用此方法。否则,调用此方法将导致 Flash Player 引发 Error 异常。

请注意,由于已向 Flash Player 中添加了新功能,因此当发布到 Flash Player 10 时,一次只可以激活下列操作中的一个操作:FileReference.browse()FileReference.upload()FileReference.download()FileReference.load()FileReference.save()。否则,Flash Player 会引发运行时错误(代码 2174)。使用 FileReference.cancel() 可停止正在进行的操作。此限制仅适用于 Flash Player 10。早期版本的 Flash Player 在同时进行多个操作时不会受到此限制的影响。

在 Adobe AIR 中,文件浏览对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。

参数

typeFilter:Array (default = null) — 一个 FileFilter 实例数组,用于过滤在对话框中显示的文件。如果省略此参数,则显示所有文件。有关详细信息,请参阅 FileFilter 类。

返回
Boolean — 如果参数有效并且打开了文件浏览对话框,则返回 true

事件
select:Event — 当用户从浏览文件选择器成功选择了项目时调度。
 
cancel:Event — 当用户取消文件上载浏览窗口时调度。

引发
IllegalOperationError — 在以下情况下引发:1) 另一个 FileReference 或 FileReferenceList 浏览会话正在进行中;每次仅能执行一个文件浏览会话。2) 用户 mms.cfg 文件中的某个设置禁止此操作。
 
ArgumentError — 如果 typeFilter 数组包含格式不正确的 FileFilter 对象,将引发异常。有关 FileFilter 对象正确格式的信息,请参阅 FileFilter 类。
 
Error — 为了响应用户动作(如鼠标事件或按键事件),将不会调用此方法。

相关 API 元素

select 事件
cancel 事件
FileReference.download()
FileReferenceList.browse()
File.browseForDirectory()
File.browseForOpen()
File.browseForOpenMultiple()
File.browseForSave()

cancel

()方法 
public function cancel():void

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

取消正在对该 FileReference 对象执行的任何上载或下载操作。调用此方法并不会调度 cancel 事件。仅在用户通过退出文件上载或下载对话框来取消操作时,才会调度该事件。

download

()方法 
public function download(request:URLRequest, defaultFileName:String = null):void

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

打开对话框,以允许用户从远程服务器下载文件。虽然 Flash Player 没有限制可上载或下载的文件的大小,但是播放器正式支持的上载或下载文件大小最大为 100 MB。

download() 方法首先打开一个操作系统对话框,让用户输入文件名并在本地计算机上选择用于保存文件的位置。用户选择了位置并确认下载操作时(例如,单击“保存”)后,开始从远程服务器下载。侦听器接收事件来表示下载的进度、成功或失败。为了在调用 download() 后确定对话框和下载操作的状态, 代码必须对 cancelopenprogresscomplete 等事件进行侦听。

FileReference.upload()FileReference.download() 函数是非阻塞式的。这些函数在调用它们之后即返回,而不会等待文件传输完成。此外,若 FileReference 对象离开作用域,则对该对象尚未完成的上载或下载操作将在它离开作用域后被取消。只要希望上载或下载操作继续,就应确保将 FileReference 对象保留在作用域中。

成功下载文件之后,将使用本地文件的属性填充 FileReference 对象的属性。如果下载成功,将调度 complete 事件。

每次只能执行一个 browse()download() 会话(因为每次只能调用一个对话框)。

此方法支持使用 HTTP 或 HTTPS 下载任何文件类型。

无法连接到常用的保留端口。有关已阻止的端口的完整列表,请参阅《ActionScript 3.0 开发人员指南》中的“限制网络 API”。

注意:如果服务器要求用户身份验证,则只有在浏览器中运行的 SWF 文件(即使用浏览器插件或 ActiveX 控件的文件)才可以提供对话框来提示用户输入用户名和密码以进行身份验证,并且只适用于下载。对于使用插件或 ActiveX 控件进行的上载操作,以及使用独立或外部播放器进行的上载和下载操作,文件传输会失败。

使用此方法时,请考虑 Flash Player 安全模型:

  • 如果执行调用的 SWF 文件在不受信任的本地沙箱中,则不允许进行加载操作。
  • 默认行为是拒绝沙箱之间的访问。网站可通过添加 URL 策略文件来实现对资源的访问。
  • 可以在包含 SWF 内容的 HTML 页中设置 objectembed 标签的 allowNetworking 参数,防止 SWF 文件使用此方法。
  • 在 Flash Player 10 和 Flash Player 9 Update 5 中,只有响应用户事件(例如,在鼠标单击或按键事件的事件处理函数中)才能成功调用此方法。否则,调用此方法将导致 Flash Player 引发 Error 异常。

在 Adobe AIR 中应用程序安全沙箱中的内容(使用 AIR 应用程序安装的内容)不受这些安全限制的约束。

有关安全性的详细信息,请参阅 Flash Player 开发人员中心主题:安全性

使用此方法下载文件时,将其标记为在标记下载的文件的操作系统上下载:

  • Windows XP Service Pack 2 和更高版本,在 Windows Vista 上
  • Mac OS 10.5 和更高版本

有些操作系统(例如 Linux)不标记下载的文件。

请注意,由于已向 Flash Player 中添加了新功能,因此当发布到 Flash Player 10 时,一次只可以激活下列操作中的一个操作:FileReference.browse()FileReference.upload()FileReference.download()FileReference.load()FileReference.save()。否则,Flash Player 会引发运行时错误(代码 2174)。使用 FileReference.cancel() 可停止正在进行的操作。此限制仅适用于 Flash Player 10。早期版本的 Flash Player 在同时进行多个操作时不会受到此限制的影响。

在 Adobe AIR 中,下载对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。 要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。

参数

request:URLRequest — URLRequest 对象。URLRequest 对象的 url 属性应包含要下载到本地计算机的文件的 URL。若此参数为 null,将引发异常。URLRequest 对象的 requestHeaders 属性将被省略;上载或下载时不支持自定义 HTTP 请求标头。要向服务器发送 POST 或 GET 参数,请将 URLRequest.data 的值设置为您的参数,并将 URLRequest.method 设置为 URLRequestMethod.POSTURLRequestMethod.GET

在某些浏览器上,URL 字符串长度受限。在某些浏览器或服务器上,长度超过 256 个字符的字符串可能失败。

 
defaultFileName:String (default = null) — 对话框中显示的要下载文件的默认文件名。此字符串不能包含以下字符:/ \ : * ? " < > | %

如果省略此参数,将分析出远程 URL 的文件名并用作默认文件名。


事件
open:Event — 当下载操作开始时调度。
 
progress:ProgressEvent — 在文件下载操作期间进行定期调度。
 
complete:Event — 当文件下载操作成功完成时调度。
 
cancel:Event — 当用户取消对话框时调度。
 
select:Event — 当用户从对话框中选择要下载的文件时调度。
 
securityError:SecurityErrorEvent — 当由于安全错误导致下载失败时调度。
 
ioError:IOErrorEvent — 由于下列任一原因进行调度:
  • 读取或传输文件期间发生输入/输出错误。
  • 在 Flash Player 的独立或外部版本中运行的 SWF 内容尝试从需要身份验证的服务器下载文件。在下载期间,独立播放器和外部播放器不为用户提供用于输入密码的方法。如果这些播放器中的 SWF 文件尝试从要求身份验证的服务器下载文件,则下载会失败。只有在 ActiveX 控件和浏览器插件播放器中,文件下载才有可能成功。

引发
IllegalOperationError — 在以下情况下引发:1) 另一个浏览会话正在进行中;每次仅能执行一个文件浏览会话。2) 传递给 request 的值不包含有效的路径或协议。3) 要下载的文件的名称中包含禁止使用的字符。4) 用户 mms.cfg 文件中的某个设置禁止此操作。
 
SecurityError — 本地不受信任的内容可能无法与 Internet 进行通信。要避免这种情况,请将此 SWF 文件重新分类为只能与远程内容交互或受信任。引发此异常时会显示一条消息,指明由于本地文件安全性限制而不允许访问的文件名和 URL。
 
SecurityError — 无法连接到常用的保留端口。有关已阻止的端口的完整列表,请参阅《ActionScript 3.0 开发人员指南》中的“限制网络 API”。
 
ArgumentError — 如果 url.data 为 ByteArray 类型,将引发异常。当与 FileReference.upload()FileReference.download() 方法一起使用时,url.data 只能为 URLVariables 或 String 类型。
 
MemoryError — 发生此错误的原因有:1) Flash Player 无法将 URLRequest.data 参数从 UTF8 转换为 MBCS。如果传递给 FileReference.download() 方法的 URLRequest 对象设置为执行 GET 操作并且 System.useCodePage 设置为 true,将发生该错误。2) Flash Player 无法为 POST 数据分配内存。如果传递给 FileReference.download() 方法的 URLRequest 对象设置为执行 POST 操作,将发生该错误。
 
Error — 为了响应用户动作(如鼠标事件或按键事件),将不会调用此方法。

相关 API 元素


示例  ( 如何使用本示例 )

下面的示例演示 download 事件对象的用法。要运行此示例,请将 downloadURL.url 属性更改为指向一个实际的域和文件,而不是虚拟的 http://www.[yourDomain].com/SomeFile.pdf。您可能还需要编译 SWF 文件,将“本地播放安全性”设置为“只访问网络”,或更新 Flash Player 的安全设置,以允许此文件网络访问。
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;
    import flash.net.FileFilter;

    public class FileReference_download extends Sprite {
        private var downloadURL:URLRequest;
        private var fileName:String = "SomeFile.pdf";
        private var file:FileReference;

        public function FileReference_download() {
            downloadURL = new URLRequest();
            downloadURL.url = "http://www.[yourDomain].com/SomeFile.pdf";
            file = new FileReference();
            configureListeners(file);
            file.download(downloadURL, fileName);
        }

        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.CANCEL, cancelHandler);
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            dispatcher.addEventListener(Event.SELECT, selectHandler);
        }

        private function cancelHandler(event:Event):void {
            trace("cancelHandler: " + event);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        private function selectHandler(event:Event):void {
            var file:FileReference = FileReference(event.target);
            trace("selectHandler: name=" + file.name + " URL=" + downloadURL.url);
        }
    }
}

load

()方法 
public function load():void

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

开始加载用户选择的本地文件。虽然 Flash Player 没有限制可上载、下载、加载或保存的文件的大小,但其正式支持的文件大小最大为 100 MB。对于 Flash Player 中运行的内容,必须先调用 FileReference.browse()FileReferenceList.browse() 方法,然后再调用 load() 方法。不过,应用程序沙箱中运行于 AIR 中的内容调用 File 对象的 load() 方法之前不必先调用 browse() 方法。(AIR File 类扩展了 FileReference 类。)

侦听器接收事件来表示加载的进度、成功或失败。尽管可以使用 FileReferenceList 对象让用户选择多个要加载的文件,但仍必须逐个加载这些文件。要逐个加载文件,请遍历 FileReference 对象的 FileReferenceList.fileList 数组。

Adobe AIR 还包括为读取文件提供更多选项的 FileStream 类。

FileReference.upload()FileReference.download()FileReference.load()FileReference.save() 函数均不分块。这些函数在调用它们之后即返回,而不会等待文件传输完成。此外,如果 FileReference 对象离开作用域,则该对象中尚未完成的任何事务将在离开作用域时被取消。只要希望上载、下载、加载或保存能继续,就应确保将 FileReference 对象保留在作用域中。

如果文件成功完成加载,则其内容将作为字节数组存储在 FileReference 对象的 data 属性中。

有以下安全事项需要注意:

  • 如果执行调用的 SWF 文件在不受信任的本地沙箱中,则不允许进行加载操作。
  • 默认行为是拒绝沙箱之间的访问。网站可通过添加跨域策略文件来实现对资源的访问。
  • 可以在包含 内容的 HTML 页中设置 objectembed 标签的 allowNetworking 参数,防止 SWF 文件使用此方法。

不过,这些注意事项不适用于应用程序沙箱中的 AIR 内容。

请注意,当发布到 Flash Player 10 或 AIR 1.5 时,一次只能激活以下操作中的一项:FileReference.browse()FileReference.upload()FileReference.download()FileReference.load()FileReference.save()。否则,应用程序将引发运行时错误(代码 2174)。使用 FileReference.cancel() 可停止正在进行的操作。此限制仅适用于 Flash Player 10 和 AIR 1.5。早期版本的 Flash Player 或 AIR 在同时进行多个操作时不会受到此限制的影响。

在 Adobe AIR 中,文件浏览对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。


事件
open:Event — 在加载操作开始时调度。
 
progress:ProgressEvent — 在文件加载操作期间定期调度。
 
complete:Event — 在文件加载操作成功完成时调度。
 
ioError:IOErrorEvent — 在应用程序读取或写入文件期间由于发生输入/输出错误而导致加载失败时调用。

引发
IllegalOperationError — 在以下情况下引发:1) 另一个 FileReference 或 FileReferenceList 浏览会话正在进行中;每次仅能执行一个文件浏览会话。2) 用户 mms.cfg 文件中的某个设置禁止此操作。
 
MemoryError — 如果应用程序无法为文件分配内存,则可能会发生此错误。文件可能太大,或者可用的内存可能太小。

相关 API 元素


示例  ( 如何使用本示例 )

下面的示例从本地文件系统向根显示对象(本例中为舞台)上载图像。示例由 Andre Venancio 提供。
var buttonShape:Shape = new Shape();
buttonShape.graphics.beginFill(0x336699);
buttonShape.graphics.drawCircle(50, 50, 25);
var button = new SimpleButton(buttonShape, buttonShape, buttonShape, buttonShape);
addChild(button);

var fileRef:FileReference= new FileReference();
button.addEventListener(MouseEvent.CLICK, onButtonClick);

function onButtonClick(e:MouseEvent):void {
fileRef.browse([new FileFilter("Images", "*.jpg;*.gif;*.png")]);
fileRef.addEventListener(Event.SELECT, onFileSelected);
}

function onFileSelected(e:Event):void {
fileRef.addEventListener(Event.COMPLETE, onFileLoaded);
fileRef.load();
}

function onFileLoaded(e:Event):void {
var loader:Loader = new Loader();
loader.loadBytes(e.target.data);
addChild(loader);
}

    requestPermission

()方法 
public function requestPermission():void

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

申请文件系统访问权限


事件
PermissionStatus:PermissionEvent — 当用户授予/拒绝所申请权限时调度。

save

()方法 
public function save(data:*, defaultFileName:String = null):void

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

打开一个对话框,允许用户将文件保存到本地文件系统。虽然 Flash Player 没有限制可上载、下载、加载或保存的文件的大小,但是播放器正式支持的文件大小最大为 100 MB。

save() 方法首先打开一个操作系统对话框,让用户输入文件名并在本地计算机上选择用于保存文件的位置。当用户选择了位置并确认保存操作时(例如通过单击“保存”),保存过程即会开始。侦听器接收事件来表示保存操作的进度、成功或失败。为了在调用 save() 后确定对话框和保存操作的状态,代码必须对 cancelopenprogresscomplete 等事件进行侦听。

Adobe AIR 还包括为本地保存文件提供更多选项的 FileStream 类。

FileReference.upload()FileReference.download()FileReference.load()FileReference.save() 函数均不分块。这些函数在调用它们之后即返回,而不会等待文件传输完成。此外,如果 FileReference 对象离开作用域,则该对象中尚未完成的任何事务将在离开作用域时被取消。只要希望上载、下载、加载或保存能继续,就应确保将 FileReference 对象保留在作用域中。

在成功保存文件之后,将使用本地文件的属性填充 FileReference 对象的属性。如果保存成功,将调度 complete 事件。

每次只能执行一个 browse()save() 会话(因为每次只能调用一个对话框)。

在 Flash Player 中,只有在响应用户事件(例如,在鼠标单击或按键事件的事件处理函数中)时才能成功调用此方法。否则,调用此方法将导致 Flash Player 引发 Error 异常。此限制不适用于应用程序沙箱中的 AIR 内容。

在 Adobe AIR 中,保存对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。 要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。

参数

data:* — 要保存的数据。数据可以采用几种格式之一,并将进行适当处理:
  • 如果值为 null,则应用程序将引发 ArgumentError 异常。
  • 如果值为 String,则将其保存为 UTF-8 文本文件。
  • 如果值为 XML,则会以 XML 格式将其写入到文本文件,并保留所有格式设置。
  • 如果值为 ByteArray 对象,则会将其逐字写入到数据文件。
  • 如果值并非以上任何一种,则 save() 方法将调用对象的 toString() 方法,将数据转换为字符串,然后将数据保存为文本文件。如果该操作失败,则应用程序将引发 ArgumentError 异常。
 
defaultFileName:String (default = null) — 对话框中显示的要保存文件的默认文件名。此字符串不能包含以下字符:/ \ : * ? " < > | %

如果 File 对象调用此方法,则文件名将为 File 对象所引用文件的名称。(AIR File 类扩展了 FileReference 类。)


事件
open:Event — 当下载操作开始时调度。
 
progress:ProgressEvent — 在文件下载操作期间进行定期调度。
 
complete:Event — 当文件下载操作成功完成时调度。
 
cancel:Event — 当用户取消对话框时调度。
 
select:Event — 当用户从对话框中选择要下载的文件时调度。
 
ioError:IOErrorEvent — 读取或传输文件期间发生输入/输出错误时调度。

引发
IllegalOperationError — 在以下情况下引发:1) 另一个浏览会话正在进行中;每次仅能执行一个文件浏览会话。2) 要下载的文件的名称中包含禁止使用的字符。3) 用户 mms.cfg 文件中的某个设置禁止此操作。
 
ArgumentError — 如果 data 的类型不是 ByteArray,并且不具有 toString() 方法,则将引发异常。如果 data 的类型不是 XML,并且不具有 toXMLString() 方法,则将引发异常。
 
Error — 为了响应用户动作(如鼠标事件或按键事件),将不会调用此方法。
 
MemoryError — 如果 Flash Player 无法为该文件分配内存,则可能会发生此错误。文件可能太大,或者可用的内存可能太小。

相关 API 元素


示例  ( 如何使用本示例 )

以下示例将键入到文本字段的内容保存到文件。该示例创建一个可编辑的文本字段 (MyTextField),创建另一不可编辑的文本字段 (MyButtonField) 作为“按钮”以响应鼠标单击。用户可以编辑第一个文本字段并单击按钮,将文本字段内容保存到本地文件。鼠标单击事件处理函数 clickhandler 使用 FileReference.save() 方法(针对名为 MyFileReference 的 FileReference 对象)打开用户当前操作系统中的对话框,因此用户可以将内容保存为本地文件,使用用户提供的名称作为文件名。
var MyTextField:TextField = new TextField();
var MyButtonField:TextField = new TextField();
var MyFile:FileReference = new FileReference();

MyTextField.border = true;
MyTextField.type = TextFieldType.INPUT;

MyButtonField.background = true;
MyButtonField.backgroundColor = 0x339933;
MyButtonField.x = 150;
MyButtonField.height = 20;
MyButtonField.text = "Click here to save";

addChild(MyTextField);
addChild(MyButtonField);
MyButtonField.addEventListener(MouseEvent.CLICK, clickhandler);

function clickhandler(e:MouseEvent): void {
    MyFile.save(MyTextField.text);
}

upload

()方法 
public function upload(request:URLRequest, uploadDataFieldName:String = "Filedata", testUpload:Boolean = false):void

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

开始将文件上载到远程服务器。虽然 Flash Player 没有限制可上载或下载的文件的大小,但是播放器正式支持的上载或下载文件大小最大为 100 MB。调用此方法之前,必须先调用 FileReference.browse()FileReferenceList.browse() 方法。

对于扩展 FileReference 类的 Adobe AIR File 类,可以使用 upload() 方法上载任何文件。对于在 Flash Player 中使用的 FileReference 类,用户必须首先选择一个文件。

侦听器接收事件来表示上载的进度、成功或失败。尽管可以使用 FileReferenceList 对象让用户选择多个要上载的文件,但必须逐个上载文件。为此,需遍历由 FileReference 对象组成的 FileReferenceList.fileList 数组。

FileReference.upload()FileReference.download() 函数是非阻塞式的。这些函数在调用它们之后即返回,而不会等待文件传输完成。此外,若 FileReference 对象离开作用域,则对该对象尚未完成的上载或下载操作将在它离开作用域后被取消。只要希望上载或下载操作继续,就应确保将 FileReference 对象保留在作用域中。

文件上载到在 url 参数中传递的 URL。该 URL 必须是配置为接受上载的服务器脚本。Flash Player 使用 HTTP POST 方法上载文件。处理上载的服务器脚本应收到包含下列元素的 POST 请求:

  • Content-Type ,属于 multipart/form-data
  • Content-Disposition,其 name 属性默认情况下设置为 "Filedata"filename 属性设置为原始文件的名称
  • 文件的二进制内容

无法连接到常用的保留端口。有关已阻止的端口的完整列表,请参阅《ActionScript 3.0 开发人员指南》中的“限制网络 API”。

对于范例 POST 请求,请参阅有关 uploadDataFieldName 参数的描述。可以使用 upload() 方法向服务器发送 POSTGET 参数,请参阅有关 request 参数的描述。

如果 testUpload 参数为 true,并且要上载的文件大于约 10 KB,则基于 Windows 的 Flash Player 在上载实际的文件之前,会先发送不带内容的测试上载 POST 操作,以验证传输操作是否可能成功。之后,Flash Player 会再次发送 POST 操作,这时其中将包含实际的文件内容。对于小于 10 KB 的文件,Flash Player 则仅执行一次上载 POST 操作,其中包含要上载的实际文件内容。基于 Macintosh 的 Flash Player 不执行测试上载 POST 操作。

注意:如果服务器要求用户身份验证,则只有在浏览器中运行的 SWF 文件(即使用浏览器插件或 ActiveX 控件的文件)才可以提供对话框来提示用户输入用户名和密码以进行身份验证,并且只适用于下载。对于使用插件或 ActiveX 控件进行的上载操作,以及使用独立或外部播放器进行的上载和下载操作,文件传输会失败。

使用此方法时,请考虑 Flash Player 安全模型:

  • 如果执行调用的 SWF 文件在不受信任的本地沙箱中,则不允许进行加载操作。
  • 默认行为是拒绝沙箱之间的访问。网站可通过添加 URL 策略文件来实现对资源的访问。
  • 可以在包含 SWF 内容的 HTML 页中设置 objectembed 标签的 allowNetworking 参数,防止 SWF 文件使用此方法。

但在 Adobe AIR 中,application 安全沙箱中的内容(使用 AIR 应用程序安装的内容)不受这些安全限制的约束。

有关安全性的详细信息,请参阅 Flash Player 开发人员中心主题:安全性

请注意,由于已向 Flash Player 中添加了新功能,因此当发布到 Flash Player 10 时,一次只可以激活下列操作中的一个操作:FileReference.browse()FileReference.upload()FileReference.download()FileReference.load()FileReference.save()。否则,Flash Player 会引发运行时错误(代码 2174)。使用 FileReference.cancel() 可停止正在进行的操作。此限制仅适用于 Flash Player 10。早期版本的 Flash Player 在同时进行多个操作时不会受到此限制的影响。

参数

request:URLRequest — URLRequest 对象,URLRequest 对象的 url 属性应包含特定服务器脚本的 URL,该服务器脚本被配置为通过 HTTP POST 调用处理上载。在某些浏览器上,URL 字符串长度受限。在某些浏览器或服务器上,长度超过 256 个字符的字符串可能失败。若此参数为 null,将引发异常。URLRequest 对象的 requestHeaders 属性将被省略;上载或下载时不支持自定义 HTTP 请求标头。

该 URL 可以是 HTTP,或者为了安全地进行上载,也可以是 HTTPS。要使用 HTTPS,请在 url 参数中使用 HTTPS URL。如果在 url 参数中没有指定端口号,则默认情况下,将使用端口 80(对于 HTTP)或端口 443(对于 HTTPS)。

要向服务器发送 POSTGET 参数,请将 URLRequest 对象的 data 属性设置为您的参数,并将 method 属性设置为 URLRequestMethod.POSTURLRequestMethod.GET

 
uploadDataFieldName:String (default = "Filedata") — 在上载 POST 操作中位于文件数据之前的字段名。uploadDataFieldName 值必须为非空字符串。默认情况下,uploadDataFieldName 的值为 "Filedata",如下面的范例 POST 请求所示:
    Content-Type: multipart/form-data; boundary=AaB03x
    --AaB03x 
    Content-Disposition: form-data; name="Filedata"; filename="example.jpg" 
    Content-Type: application/octet-stream
    ... contents of example.jpg ... 
    --AaB03x-- 
    
 
testUpload:Boolean (default = false) — 请求上载测试文件的设置。如果 testUploadtrue,则对于大于 10 KB 的文件,Flash Player 将尝试进行内容长度为 0 的测试文件上载 POST。测试上载将检查实际文件上载是否可能成功,以及服务器身份验证(如果需要)是否可能成功。测试上载仅适用于 Windows 播放器。


事件
open:Event — 当上载操作开始时调度。
 
progress:ProgressEvent — 在文件上载操作期间进行定期调度。
 
complete:Event — 当文件上载操作成功完成时调度。
 
uploadCompleteData:DataEvent — 成功上载文件并从服务器接收数据之后调度。
 
securityError:SecurityErrorEvent — 由于安全错误导致上载失败时调度。
 
httpStatus:HTTPStatusEvent — 由于 HTTP 错误导致上载失败时调度。
 
httpResponseStatus:HTTPStatusEvent — 上载操作成功完成,服务器返回响应 URL 和响应标头。
 
ioError:IOErrorEvent — 在下列任一情形下调用:
  • 由于 Flash Player 或 Adobe AIR 在读/写或传输文件期间发生输入/输出错误,导致上载失败。
  • 由于试图将文件上载到要求身份验证(如用户名和密码)的服务器,上载失败。在上载过程中,没有为用户提供输入密码的方式。
  • 由于 url 参数包含无效协议,导致上载失败。FileReference.upload() 必须使用 HTTP 或 HTTPS。

引发
SecurityError — 本地不受信任的 SWF 文件可能无法与 Internet 进行通信。要避免这种情况,请将此 SWF 文件重新分类为只能与远程内容交互或受信任。引发此异常时会附带一个消息,指明不允许访问的本地文件和 URL 的名称。
 
SecurityError — 无法连接到常用的保留端口。有关已阻止的端口的完整列表,请参阅《ActionScript 3.0 开发人员指南》中的“限制网络 API”。
 
IllegalOperationError — 在以下情况下引发:1) 另一个 FileReference 或 FileReferenceList 浏览会话正在进行中;每次仅能执行一个文件浏览会话。2) URL 参数为无效的路径或协议。文件上载必须使用 HTTP 协议,文件下载则必须使用 FTP 或 HTTP 协议。3) uploadDataFieldName 参数设置为 null。4) 用户 mms.cfg 文件中的某个设置禁止此操作。
 
ArgumentError — 在以下情况下引发:1) uploadDataFieldName 参数为空字符串。2) url.data 为 ByteArray 类型。当与 FileReference.upload()FileReference.download() 方法一起使用时,url.data 只能为 URLVariables 或 String 类型。3) 在 AIR 运行时中(在应用程序安全沙箱中),URLRequest 的方法不是 GET 和 POST(而是使用 uploadEncoded())。
 
MemoryError — 发生此错误的原因有:1) Flash Player 无法将 URLRequest.data 参数从 UTF8 转换为 MBCS。如果传递给 FileReference.upload() 的 URLRequest 对象设置为执行 GET 操作并且 System.useCodePage 设置为 true,将发生该错误。2) Flash Player 无法为 POST 数据分配内存。如果传递给 FileReference.upload() 的 URLRequest 对象设置为执行 POST 操作,将发生该错误。

相关 API 元素

    uploadUnencoded

()方法 
public function uploadUnencoded(request:URLRequest):void

运行时版本: AIR 1.0

启动将文件上载到 URL 的操作,不进行任何编码。由于 upload() 方法会在 form-data 封套中对文件进行编码,因此 uploadUnencoded() 方法会在 HTTP 请求正文中按原样传递文件内容。如果要发送的数据已编码为接收服务器能够理解的格式,请使用 uploadUnencoded() 方法。uploadeUnencoded() 方法通常与 HTTP/WebDAV PUT 方法一起使用。

参数

request:URLRequest — URLRequest 对象,URLRequest 对象的 url 属性应包含特定服务器脚本的 URL,该服务器脚本被配置为通过 HTTP POST 调用处理上载。在某些浏览器上,URL 字符串长度受限。在某些浏览器或服务器上,长度超过 256 个字符的字符串可能失败。若此参数为 null,将引发异常。

该 URL 可以是 HTTP,或者为了安全地进行上载,也可以是 HTTPS。要使用 HTTPS,请在 url 参数中使用 HTTPS URL。如果在 url 参数中没有指定端口号,则默认情况下,将使用端口 80(对于 HTTP)或端口 443(对于 HTTPS)。

要向服务器发送 POSTGET 参数,请将 URLRequest 对象的 data 属性设置为您的参数,并将 method 属性设置为 URLRequestMethod.POSTURLRequestMethod.GET


事件
open:Event — 当上载操作开始时调度。
 
progress:ProgressEvent — 在文件上载操作期间进行定期调度。
 
complete:Event — 当文件上载操作成功完成时调度。
 
uploadCompleteData:DataEvent — 成功上载文件并从服务器接收数据之后调度。
 
securityError:SecurityErrorEvent — 由于安全错误导致上载失败时调度。
 
httpStatus:HTTPStatusEvent — 由于 HTTP 错误导致上载失败时调度。
 
httpResponseStatus:HTTPStatusEvent — 上载操作成功完成,服务器返回响应 URL 和响应标头。
 
ioError:IOErrorEvent — 在下列任一情形下调用:
  • 由于 Adobe AIR 在读/写或传输文件期间发生输入/输出错误,导致上载失败。
  • 由于试图将文件上载到要求身份验证(如用户名和密码)的服务器,上载失败。在上载过程中,没有为用户提供输入密码的方式。
  • 由于 url 参数包含无效协议,导致上载失败。FileReference.upload() 必须使用 HTTP 或 HTTPS。

引发
SecurityError — 本地不受信任的 SWF 文件可能无法与 Internet 进行通信。要避免这种情况,请将此 SWF 文件重新分类为只能与远程内容交互或受信任。引发此异常时会附带一个消息,指明不允许访问的本地文件和 URL 的名称。
 
IllegalOperationError — 在以下情况下引发:1) 另一个 FileReference 或 FileReferenceList 浏览会话正在进行中;每次仅能执行一个文件浏览会话。2) URL 参数为无效的路径或协议。文件上载必须使用 HTTP。

相关 API 元素

事件详细信息

cancel

事件
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.CANCEL

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

当用户通过文件浏览对话框取消文件上载或下载时调度。如果用户通过其他方式(关闭浏览器或停止当前应用程序)取消上载或下载,则 Flash Player 不会调度该事件。

Event.CANCEL 常量定义 cancel 事件对象的 type 属性的值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target对已取消其操作的对象的引用。

示例  ( 如何使用本示例 )

下面的示例演示 cancel 事件对象的用法。要运行此示例,请将 downloadURL.url 属性更改为指向一个实际的域和文件,而不是虚拟的 http://www.[yourDomain].com/SomeFile.pdf。您可能还需要编译 SWF 文件,将“本地播放安全性”设置为“只访问网络”,或更新 Flash Player 的安全设置,以允许此文件网络访问。
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;

    public class FileReference_event_cancel extends Sprite {
        private var downloadURL:URLRequest;
        private var fileName:String = "SomeFile.pdf";
        private var file:FileReference;

        public function FileReference_event_cancel() {
            downloadURL = new URLRequest();
            downloadURL.url = "http://www.[yourDomain].com/SomeFile.pdf";
            file = new FileReference();
            file.addEventListener(Event.CANCEL, cancelHandler);
            file.download(downloadURL, fileName);
        }
        private function cancelHandler(event:Event):void {
            trace("cancelHandler: " + event);
        }
    }
}

complete

事件  
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.COMPLETE

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

当下载操作完成或上载操作生成 HTTP 状态代码 200 时调度。对于文件下载操作,在 Flash Player 或 Adobe AIR 将整个文件下载到磁盘上时调度此事件。对于文件上载操作,在 Flash Player 或 Adobe AIR 接收到 HTTP 状态代码 200(来自接收传输的服务器)之后调度此事件。

Event.COMPLETE 常量定义 complete 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target已完成加载的网络对象。

示例  ( 如何使用本示例 )

下面的示例演示 complete 事件对象的用法。要运行此示例,请将 downloadURL.url 属性更改为指向一个实际的域和文件,而不是虚拟的 http://www.[yourDomain].com/SomeFile.pdf。您可能还需要编译 SWF 文件,将“本地播放安全性”设置为“只访问网络”,或更新 Flash Player 的安全设置,以允许此文件网络访问。
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;

    public class FileReference_event_complete extends Sprite {
        private var downloadURL:URLRequest;
        private var fileName:String = "SomeFile.pdf";
        private var file:FileReference;

        public function FileReference_event_complete() {
            downloadURL = new URLRequest();
            downloadURL.url = "http://www.[yourDomain].com/SomeFile.pdf";
            file = new FileReference();
            configureListeners(file);
            file.download(downloadURL, fileName);
        }

        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.CANCEL, cancelHandler);
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            dispatcher.addEventListener(Event.SELECT, selectHandler);
        }

        private function cancelHandler(event:Event):void {
            trace("cancelHandler: " + event);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        private function selectHandler(event:Event):void {
            var file:FileReference = FileReference(event.target);
            trace("selectHandler: name=" + file.name + " URL=" + downloadURL.url);
        }
    }
}

相关 API 元素

    

httpResponseStatus

事件  
事件对象类型: flash.events.HTTPStatusEvent
属性 HTTPStatusEvent.type = flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS

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

upload()uploadUnencoded() 方法调用尝试通过 HTTP 访问数据,并且 Adobe AIR 可以检测并返回请求的状态代码时调度。

httpStatus 事件不同,httpResponseStatus 事件在传送任何响应数据之前传送。此外,httpResponseStatus 事件还包括 responseHeadersresponseURL 属性的值(对于 httpStatus,这些属性未定义)。请注意,在发送任何 completeerror 事件之前还将发送 httpResponseStatus(如果有)。

HTTPStatusEvent.HTTP_RESPONSE_STATUS 常量定义 httpResponseStatus 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
responseURL从中返回响应的 URL。
responseHeaders响应以 URLRequestHeader 对象的数组形式返回的响应标头。
status由服务器返回的 HTTP 状态代码。
redirected响应是否为重定向结果。
target接收 HTTP 状态代码的网络对象。

相关 API 元素

httpStatus

事件  
事件对象类型: flash.events.HTTPStatusEvent
属性 HTTPStatusEvent.type = flash.events.HTTPStatusEvent.HTTP_STATUS

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

当上载失败并且存在可用来描述失败的 HTTP 状态代码时调度。调度 httpStatus 事件之后,将调度 ioError 事件。

仅在上载失败时才调度 httpStatus 事件。对于在 Flash Player 中运行的内容,此事件不适用于下载失败。如果下载由于 HTTP 错误而失败,则将错误报告为 I/O 错误。

HTTPStatusEvent.HTTP_STATUS 常量定义 httpStatus 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
status由服务器返回的 HTTP 状态代码。
target接收 HTTP 状态代码的网络对象。

相关 API 元素

ioError

事件  
事件对象类型: flash.events.IOErrorEvent
属性 IOErrorEvent.type = flash.events.IOErrorEvent.IO_ERROR

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

当上载或下载失败时调度。文件传输会失败的原因有:

  • 当播放器正在读取、写入或传输文件时发生输入/输出错误。
  • SWF 文件尝试将文件上载到要求身份验证(如用户名和密码)的服务器。在上载期间,Flash Player 或 Adobe AIR 不为用户提供输入密码的方法。如果 SWF 文件尝试将文件上载到要求身份验证的服务器,上载将失败。
  • SWF 文件尝试在独立或外部播放器中从要求身份验证的服务器下载文件。在下载期间,独立播放器和外部播放器不提供用户用于输入密码的方法。如果这些播放器中的 SWF 文件尝试从要求身份验证的服务器下载文件,则下载会失败。文件下载只能在 ActiveX 控件、浏览器插件播放器和 Adobe AIR 运行时中成功。
  • 传递到 upload() 方法中的 url 参数的值包含无效协议。有效协议包括 HTTP 和 HTTPS。

重要说明:只有在浏览器中运行的应用程序(即,使用浏览器插件或 ActiveX 控件的应用程序)和在 Adobe AIR 中运行的内容才可以提供对话框来提示用户输入用户名和密码以进行身份验证,并且只适用于下载。对于使用插件或 ActiveX 控件版本的 Flash Player 进行的上载操作,以及使用独立播放器或外部播放器进行的上载或下载操作,文件传输将失败。

定义 ioError 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
errorID与特定错误关联的引用编号(仅限 AIR)。
target发生输入/输出错误的网络对象。
text要显示为错误消息的文本。

相关 API 元素

open

事件  
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.OPEN

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

当上载或下载操作开始时调度。

Event.OPEN 常量用于定义 open 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target已打开连接的网络对象。

示例  ( 如何使用本示例 )

下面的示例演示 download 事件对象的用法。要运行此示例,请将 downloadURL.url 属性更改为指向一个实际的域和文件,而不是虚拟的 http://www.[yourDomain].com/SomeFile.pdf。您可能还需要编译 SWF 文件,将“本地播放安全性”设置为“只访问网络”,或更新 Flash Player 的安全设置,以允许此文件网络访问。
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;
    import flash.net.FileFilter;

    public class FileReference_download extends Sprite {
        private var downloadURL:URLRequest;
        private var fileName:String = "SomeFile.pdf";
        private var file:FileReference;

        public function FileReference_download() {
            downloadURL = new URLRequest();
            downloadURL.url = "http://www.[yourDomain].com/SomeFile.pdf";
            file = new FileReference();
            configureListeners(file);
            file.download(downloadURL, fileName);
        }

        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.CANCEL, cancelHandler);
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            dispatcher.addEventListener(Event.SELECT, selectHandler);
        }

        private function cancelHandler(event:Event):void {
            trace("cancelHandler: " + event);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        private function selectHandler(event:Event):void {
            var file:FileReference = FileReference(event.target);
            trace("selectHandler: name=" + file.name + " URL=" + downloadURL.url);
        }
    }
}

相关 API 元素

    

permissionStatus

事件  
事件对象类型: flash.events.PermissionEvent
属性 PermissionEvent.type = flash.events.PermissionEvent.PERMISSION_STATUS

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

当应用程序申请文件系统访问权限时调度。检查 status 属性的值,以确定是授予此权限还是拒绝此权限。

相关 API 元素

progress

事件  
事件对象类型: flash.events.ProgressEvent
属性 ProgressEvent.type = flash.events.ProgressEvent.PROGRESS

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

在文件上载或下载操作期间定期调度。progress 事件在 Flash Player 将字节传输到服务器时调度,即使传输最终没有成功,也会在传输期间定期调度。要确定文件传输是否真正成功和完成以及何时真正成功和完成,需要侦听 complete 事件。

在某些情况下,接收不到 progress 事件。例如,当所传输的文件非常小或者上载或下载速度非常快时,可能就不会调度 progress 事件。

在低于 OS X 10.3 版本的 Macintosh 平台上不能确定文件上载进度。progress 事件在上载操作期间调用,但 progress 事件的 bytesLoaded 属性值为 -1,表示不能确定进度。

定义 progress 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
bytesLoaded在侦听器处理事件时加载的项数或字节数。
bytesTotal如果加载进程成功,最终将加载的项目或字节总数。
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target报告进度的对象。

示例  ( 如何使用本示例 )

下面的示例演示 progress 事件的用法。要运行此示例,请将 downloadURL.url 属性更改为指向一个实际的域和文件,而不是虚拟的 http://www.[yourDomain].com/SomeFile.pdf。您可能还需要编译 SWF 文件,将“本地播放安全性”设置为“只访问网络”,或更新 Flash Player 的安全设置,以允许此文件网络访问。
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;

    public class FileReference_event_progress extends Sprite {
        private var downloadURL:URLRequest;
        private var fileName:String = "SomeFile.pdf";
        private var file:FileReference;

        public function FileReference_event_progress() {
            downloadURL = new URLRequest();
            downloadURL.url = "http://www.[yourDomain].com/SomeFile.pdf";
            file = new FileReference();
            file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            file.addEventListener(Event.COMPLETE, completeHandler);
            file.download(downloadURL, fileName);
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler: name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }
        
        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }
        
        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }
    }
}

相关 API 元素

securityError

事件  
事件对象类型: flash.events.SecurityErrorEvent
属性 SecurityErrorEvent.type = flash.events.SecurityErrorEvent.SECURITY_ERROR

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

当对 FileReference.upload()FileReference.download() 方法的调用尝试将文件上载到服务器,或是从调用方安全沙箱外部的服务器上下载文件时进行调度。用于描述发生的特定错误的文本属性的值通常为 "securitySandboxError"。执行调用的 SWF 可能已经尝试访问其域外部的 SWF 文件,但却无权这样做。您可以通过使用 URL 策略文件来尝试纠正此错误。

在 Adobe AIR 中,这些安全限制不适用于应用程序安全沙箱中的内容。

在 Adobe AIR 中,这些安全限制不适用于应用程序安全沙箱中的内容。

SecurityErrorEvent.SECURITY_ERROR 常量定义 securityError 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target报告安全错误的网络对象。
text要显示为错误消息的文本。

相关 API 元素

select

事件  
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.SELECT

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

当用户从文件浏览对话框选择要上载或下载的文件时调度。(调用 FileReference.browse()FileReferenceList.browse()FileReference.download() 方法时将打开此对话框。) 当用户选择文件并确认操作(例如,通过单击“确定”)时,会填充 FileReference 对象的属性。

对于在 Flash Player 内运行的内容或Adobe AIR 运行时中、但在应用程序安全沙箱以外运行的内容select 事件的行为方式略有不同,具体取决于调用该事件的方法。在调用 browse() 后调度 select 事件时,Flash Player 或 AIR 应用程序能够读取 FileReference 对象的所有属性,因为用户所选的文件位于本地文件系统上。在调用 download() 后发生 select 事件时,Flash Player 或 AIR 应用程序只能读取 name 属性,因为在调度 select 事件时,文件尚未下载到本地文件系统。如果已下载了文件,则调度 complete 事件时,Flash Player 或 AIR 应用程序可以读取 FileReference 对象的所有其他属性。

Event.SELECT 常量定义 select 事件对象的 type 属性的值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target 对象,已在其中选定了一个项目。

示例  ( 如何使用本示例 )

下面的示例演示 select 事件对象的用法。要运行此示例,请将 uploadURL.url 属性更改为指向一个实际的域和文件,而不是虚拟的 http://www.[yourDomain].com/SomeFile.pdf。您可能还需要编译 SWF 文件,将“本地播放安全性”设置为“只访问网络”,或更新 Flash Player 的安全设置,以允许此文件网络访问。要想可以从桌面运行这个示例,您的服务器还需要发送 crossdomain.xml 文件。如果触发了 ioErrorHandler() 函数,可能需要使用一个有效的 URL 来更新提供的 uploadURL,此有效的 URL 被配置成接收上载。
 
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;

    public class FileReference_event_select extends Sprite {
        private var uploadURL:URLRequest;
        private var file:FileReference;

        public function FileReference_event_select() {
            uploadURL = new URLRequest();
            uploadURL.url = "http://www.[yourDomain].com/yourUploadHandlerScript.cfm";
            file = new FileReference();
            file.addEventListener(Event.SELECT, selectHandler);
            file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            file.addEventListener(Event.COMPLETE, completeHandler);
            file.browse();
        }

        private function selectHandler(event:Event):void {
            var file:FileReference = FileReference(event.target);
            trace("selectHandler: name=" + file.name + " URL=" + uploadURL.url);
            file.upload(uploadURL);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler: name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }
    }
}

uploadCompleteData

事件  
事件对象类型: flash.events.DataEvent
属性 DataEvent.type = flash.events.DataEvent.UPLOAD_COMPLETE_DATA

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

成功上载并从服务器接收数据之后调度。如果未从服务器返回数据,则不调度此事件。

定义 uploadCompleteData 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
data成功上载文件后从服务器返回的原始数据。
target成功上载后接收数据的 FileReference 对象。
FileReferenceExample.as

下例显示在运行时加载的文件的数据格式和状态信息。

注意:要运行此示例,请更改 uploadURL.url 属性以指向实际的 URL,而不是示例中虚拟的地址。URL 应指向名为 yourUploadHandlerScript.cfm 的文件,该文件位于指定 URL 的根 Web 目录下。根据您的配置,您可能还需要编译 SWF 文件,将“本地播放安全性”设置为“只访问网络”,或更新 Flash Player 的安全设置,以允许此文件网络访问。

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileFilter;
    import flash.net.FileReference;
    import flash.net.URLRequest;

    public class FileReferenceExample extends Sprite {
        private var uploadURL:URLRequest;
        private var file:FileReference;

        public function FileReferenceExample() {
            uploadURL = new URLRequest();
            uploadURL.url = "http://www.[yourDomain].com/yourUploadHandlerScript.cfm";
            file = new FileReference();
            configureListeners(file);
            file.browse(getTypes());
        }

        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.CANCEL, cancelHandler);
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            dispatcher.addEventListener(Event.SELECT, selectHandler);
            dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
        }

        private function getTypes():Array {
            var allTypes:Array = new Array(getImageTypeFilter(), getTextTypeFilter());
            return allTypes;
        }

        private function getImageTypeFilter():FileFilter {
            return new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg;*.jpeg;*.gif;*.png");
        }

        private function getTextTypeFilter():FileFilter {
            return new FileFilter("Text Files (*.txt, *.rtf)", "*.txt;*.rtf");
        }

        private function cancelHandler(event:Event):void {
            trace("cancelHandler: " + event);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }

        private function uploadCompleteDataHandler(event:DataEvent):void {
            trace("uploadCompleteData: " + event);
        }

        private function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }
        
        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        private function selectHandler(event:Event):void {
            var file:FileReference = FileReference(event.target);
            trace("selectHandler: name=" + file.name + " URL=" + uploadURL.url);
            file.upload(uploadURL);
        }
    }
}




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

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