適用於 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 標籤
移動 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 檔。

如果沒有指定任何參數,下列樣本 HTTP POST 要求就會從 Flash Player 傳送至伺服器端程式碼:

  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
[唯讀] ByteArray 物件,代表成功呼叫 load() 方法後載入的檔案所包含的資料。
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

ByteArray 物件,代表成功呼叫 load() 方法後載入的檔案所包含的資料。



實作
    public function get data():ByteArray

擲回值
IllegalOperationError — 如果呼叫 load() 方法不成功,就會擲出例外並出現訊息,指出函數呼叫順序錯誤或之前的呼叫不成功。在此情況下,data 屬性的值會是 null
 
IOError — 如果無法開啟或讀取檔案,或者存取檔案時遇到類似的錯誤,就會擲回例外,並出現指出檔案 I/O 錯誤的訊息。在此情況下,data 屬性的值會是 null

相關 API 元素

    

extension

屬性 
extension:String  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0

副檔名。

副檔名是最後一點 (".") 後面 (不含 "." 本身) 的名稱部分。如果檔案名稱中沒有點,則副檔名為 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() 方法,則 name 屬性會在傳送 select 事件時填入。



實作
    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 屬性中在最後一個點 (.) 字元後面的部分) 會識別檔案類型。



實作
    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 更新 5 版本中,只有在回應使用者事件 (例如,在按下滑鼠或按下按鍵事件的事件處理常式中) 時,才能成功呼叫這個方法。否則,呼叫這個方法會導致 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 不受這個多項作業同時進行限制的影響。

在 Adobe AIR 中,檔案瀏覽對話方塊不一定會顯示在由其他視窗所「擁有」的視窗前面 (owner 屬性不是 Null 的視窗)。若要避免發生視窗排序問題,請在呼叫此方法之前隱藏擁有的視窗。

參數

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 event
cancel event
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」

注意: 如果伺服器需要使用者驗證,則只有在瀏覽器中執行 (也就是使用瀏覽器外掛程式或 ActiveX 控制項) 的 SWF 檔才能提供對話方塊,以提示使用者輸入可供驗證且僅供下載之用的使用者名稱和密碼。 如果使用外掛程式或 ActiveX 控制項上傳,或是使用獨立或外部播放程式進行上傳及下載,則檔案傳輸會失敗。

使用此方法時,必須顧及 Flash Player 安全性模型:

  • 如果呼叫的 SWF 檔位於不受信任的本機安全執行程序中,則不允許載入作業。
  • 預設行為是拒絕安全執行程序之間的存取。 但是網站可以新增 URL 原則檔,啟用對資源的存取。
  • 您可以拒絕 SWF 檔使用這個方法,方式是在包含 SWF 內容的 HTML 網頁中,設定 objectembed 標籤的 allowNetworking 參數。
  • 在 Flash Player 10 和 Flash Player 9 更新 5 版本中,只有在回應使用者事件 (例如,在按下滑鼠或按下按鍵事件的事件處理常式中) 時,才能成功呼叫這個方法。否則,呼叫這個方法會導致 Flash Player 擲出錯誤例外。

在 Adobe AIR 中,application 安全執行程序中的內容 (使用 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 屬性不是 Null 的視窗)。若要避免發生視窗排序問題,請在呼叫此方法之前隱藏擁有的視窗。

參數

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 — 本機不受信任的內容可能無法與網際網路進行通訊。若要避免這種情況,請將此 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 應用程式安全執行程序中執行的內容不需要先呼叫 browse() 方法,就可以呼叫 File 物件的 load() 方法 (AIR 的 File 類別乃是擴充 FileReference 類別)。

偵聽程式會接收事件,以指出載入的進度、成功或失敗。雖然可以使用 FileReferenceList 物件,讓使用者選取多個載入的檔案,但您還是必須一次只載入一個檔案。若要逐一載入每個檔案,請重複執行 FileReference 物件的 FileReferenceList.fileList 陣列。

Adobe AIR 也包含提供更多讀取檔案選項的 FileStream 類別。

FileReference.upload()FileReference.download()FileReference.load()FileReference.save() 函數都是非阻隔式函數。這些函數會在呼叫之後、檔案傳輸完成之前傳回。此外,如果 FileReference 物件超出範圍,就會在離開範圍時,取消該物件尚未完成的任何交易。如果希望上傳、下載、載入或儲存繼續進行,就必須確定 FileReference 物件保持在範圍內。

如果檔案順利載入完成,其內容會以位元組陣列形式儲存至 FileReference 物件的 data 屬性。

切記下列安全性考量:

  • 如果呼叫的 SWF 檔位於不受信任的本機安全執行程序中,則不允許載入作業。
  • 預設行為是拒絕安全執行程序之間的存取。 網站可以新增跨網域原則檔來啟用對資源的存取。
  • 如果您希望防止任何檔案使用此方法,可以在包含 SWF 內容的 HTML 頁面中,設定 objectembed 標籤的 allowNetworking 參數。

不過,這些考量事項對於應用程式安全執行程序中的 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 屬性不是 Null 的視窗)。若要避免發生視窗排序問題,請在呼叫此方法之前隱藏擁有的視窗。


事件
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 擲出錯誤例外。應用程式安全執行程序中的 AIR 內容不受此限制。

在 Adobe AIR 中,儲存對話方塊不一定會顯示在由其他視窗所「擁有」的視窗前面 (owner 屬性不是 Null 的視窗)。若要避免發生視窗排序問題,請在呼叫此方法之前隱藏擁有的視窗。

參數

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() 方法,然後再呼叫此方法。

針對 Adobe AIR 檔案類別 (擴充 FileReference 類別),您可以使用 upload() 方法以上載任何檔案。對於 FileReference 類別 (在 Flash Player 中使用),使用者必須先選擇檔案。

偵聽程式會接收事件以指出上傳的進度、成功或失敗。 雖然您可以使用 FileReferenceList 物件,讓使用者選取多個要上傳的檔案,不過必須一次上傳一個檔案。若要這樣做,請重複執行 FileReference 物件的 FileReferenceList.fileList 陣列。

FileReference.upload()FileReference.download() 都是非阻隔式函數。 這些函數會在呼叫之後、檔案傳輸完成之前傳回。此外,如果 FileReference 物件超出範圍,就會在離開範圍時,取消該物件尚未完成的任何上傳或下載。 只要想讓上傳或下載繼續進行,就必須確定 FileReference 物件保持在範圍內。

檔案會上傳到在 url 參數中傳遞的 URL。 URL 必須是設定為可以接受上傳的伺服器程式碼。 Flash Player 會使用 HTTP POST 方法來上傳檔案。 處理上傳的伺服器程式碼應該要有包含下列元素的 POST 要求:

  • Content-Type (屬於 multipart/form-data
  • name 特質預設為 "Filedata"filename 特質設為原始檔案名稱的 Content-Disposition)
  • 檔案的二進位內容

您不可以連接到常用的保留連接埠。完整的封鎖連接埠清單,請參閱在「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 作業。

注意: 如果伺服器需要使用者驗證,則只有在瀏覽器中執行 (也就是使用瀏覽器外掛程式或 ActiveX 控制項) 的 SWF 檔才能提供對話方塊,以提示使用者輸入可供驗證且僅供下載之用的使用者名稱和密碼。 如果使用外掛程式或 ActiveX 控制項上傳,或是使用獨立或外部播放程式進行上傳及下載,則檔案傳輸會失敗。

使用此方法時,必須顧及 Flash Player 安全性模型:

  • 如果呼叫的 SWF 檔位於不受信任的本機安全執行程序中,則不允許載入作業。
  • 預設行為是拒絕安全執行程序之間的存取。 但是網站可以新增 URL 原則檔,啟用對資源的存取。
  • 您可以拒絕 SWF 檔使用這個方法,方式是在包含 SWF 內容的 HTML 網頁中,設定 objectembed 標籤的 allowNetworking 參數。

但在 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 屬性應該包含設定為透過 HTTP POST 呼叫處理上傳之伺服器程式碼的 URL。 在某些瀏覽器上,URL 字串有長度上的限制。 長度超過 256 個字元,就可能在某些瀏覽器或伺服器上造成失敗。 如果此參數為 null,就會擲回例外。 URLRequest 物件的 requestHeaders 屬性會被忽略;上傳或下載不支援自訂 HTTP 要求檔頭。

URL 可以是 HTTP,如果要執行安全上傳也可以是 HTTPS。 若要使用 HTTPS,請在 url 參數中使用 HTTPS URL。 如果您未在 url 參數中指定連接埠號,預設會針對 HTTP 使用連接埠 80 而針對 HTTPS 使用連接埠 443。

若要將 POSTGET 參數傳送至伺服器,請將 URLRequest 物件的 data 屬性設定為您的參數,並將 method 屬性設定為 URLRequestMethod.POSTURLRequestMethod.GET

 
uploadDataFieldName:String (default = "Filedata") — 欄位名稱,位於上傳 POST 作業中的檔案資料前面。 uploadDataFieldName 必須是非 null 的值以及非空白的字串。 根據預設,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) — 要求測試檔案上傳的設定。 當 testUpload 是設定為 true 時,對於大於 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 檔可能無法與網際網路進行通訊。若要避免這種情況,請將此 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() 方法。一般搭配 HTTP/WebDAV PUT 方法使用 uploadeUnencoded() 方法。

參數

request:URLRequest — URLRequest 物件。URLRequest 物件的 url 屬性應該包含設定為透過 HTTP POST 呼叫處理上傳之伺服器程式碼的 URL。 在某些瀏覽器上,URL 字串有長度上的限制。 長度超過 256 個字元,就可能在某些瀏覽器或伺服器上造成失敗。 如果此參數為 null,就會擲回例外。

URL 可以是 HTTP,如果要執行安全上傳也可以是 HTTPS。 若要使用 HTTPS,請在 url 參數中使用 HTTPS URL。 如果您未在 url 參數中指定連接埠號,預設會針對 HTTP 使用連接埠 80 而針對 HTTPS 使用連接埠 443。

若要將 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 檔可能無法與網際網路進行通訊。若要避免這種情況,請將此 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 事件而定義)。請注意,httpResponseStatus (如果有的話) 將在 (另外) 任何 completeerror 事件之前傳送。

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() 方法的呼叫嘗試將檔案上傳至伺服器,或從呼叫者安全執行程序以外的伺服器取得檔案時傳送。 描述發生之特定錯誤的 text 屬性值通常會是 "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 事件的動作會根據叫用它的方法稍微不同。如果 select 事件是在呼叫 browse() 之後傳送,Flash Player 或 AIR 應用程式就可以讀取 FileReference 物件的所有屬性,因為使用者選取的檔案是在本機檔案系統上。如果 select 事件是在呼叫 download() 之後傳送,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
 
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

在成功上傳後,從伺服器接到資料以後傳送。 如果未從伺服器傳回資料,則不傳送此事件。

定義 的 type 屬性值 (uploadCompleteData 事件物件)。

這個事件具有下列屬性:

屬性
bubblesfalse
cancelablefalse;沒有要取消的預設行為指令。
currentTarget正主動使用事件偵聽程式處理 Event 物件的物件。
data成功上載檔案以後,從伺服器傳回的原始資料。
target成功上載以後,接收資料的 FileReference 物件。
FileReferenceExample.as

下列範例會顯示在執行階段下載之檔案的資料格式和狀態資訊。

注意: 如果要執行這個範例,請變更 uploadURL.url 屬性,將它指向實際的 URL,而不是範例中的虛構 URL。 URL 應該指向 URL 指定之網站根目錄中的 yourUploadHandlerScript.cfm。 根據您的設定,可能還需要編譯 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 類別就會以英文顯示。