Package | flash.net |
Class | public class FileReference |
Inheritance | FileReference Object |
Player version: | Flash Player 8 |
FileReference instances are created in two ways:
new
operator with the FileReference constructor: var myFileReference = new FileReference();
FileReferenceList.browse()
, which creates an array of FileReference objectsDuring an upload operation, all of the properties of a FileReference object are populated by calls to FileReference.browse()
or FileReferenceList.browse()
. During a download operation, the name
property is populated when onSelect
has been invoked; all other properties are populated when onComplete
has been invoked.
The browse()
method opens an operating-system dialog box which prompts the user to select any local file for upload. The FileReference.browse()
method lets the user select a single file; the FileReferenceList.browse()
method lets the user select multiple files. After a successful call to the browse()
method, call the FileReference.upload()
method to upload one file at a time. The FileReference.download()
method prompts the user for a location to save the file and initiates downloading from a remote URL.
The FileReference and FileReferenceList classes do not let you set the default file location for the dialog box generated by browse()
and download()
calls. The default location shown in the dialog box is the most recently browsed folder, if that location can be determined, or the desktop. The classes do not allow you to read from or write to the transferred file. They do not allow the SWF file that initiated the upload or download to access the uploaded or downloaded file or the file's location on the user's disk.
The FileReference and FileReferenceList classes also do not provide methods for authentication. With servers that require authentication, you can download files with the Flash Player browser plug-in, but uploading (on all players) and downloading (on the stand-alone or external player) fails. Use FileReference event listeners to ascertain whether operations have successfully completed and to handle errors.
For uploading and downloading operations, a SWF file can access files only within its own domain, including any domains that are specified by a policy file. If the SWF that is initiating the upload or download doesn't come from the same domain as the file server, you must put a policy file on the file server.
While calls to the FileReference.browse()
, FileReferenceList.browse()
, or FileReference.download()
methods are executing, SWF file playback pauses on the following platforms: Flash Players for Linux, the Flash Player plug-in for Mac OS X, the external Flash Player for Macintosh, and the stand-alone player for Mac OS X 10.1 and earlier. The SWF file continues to run in all players for Windows and in the stand-alone player for Macintosh on Mac OS X 10.2 and later.
import flash.net.FileReference; var allTypes:Array = new Array(); var imageTypes:Object = new Object(); imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)"; imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png"; allTypes.push(imageTypes); var textTypes:Object = new Object(); textTypes.description = "Text Files (*.txt, *.rtf)"; textTypes.extension = "*.txt;*.rtf"; allTypes.push(textTypes); var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("onSelect: " + file.name); if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) { trace("Upload dialog failed to open."); } } listener.onCancel = function(file:FileReference):Void { trace("onCancel"); } listener.onOpen = function(file:FileReference):Void { trace("onOpen: " + file.name); } listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); } listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); } listener.onHTTPError = function(file:FileReference):Void { trace("onHTTPError: " + file.name); } listener.onIOError = function(file:FileReference):Void { trace("onIOError: " + file.name); } listener.onSecurityError = function(file:FileReference, errorString:String):Void { trace("onSecurityError: " + file.name + " errorString: " + errorString); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse(allTypes);
See also
Property | ||
---|---|---|
creationDate : Date
[read-only]The creation date of the file on the local disk.
|
||
creator : String
[read-only]The Macintosh creator type of the file.
|
||
modificationDate : Date
[read-only]The date that the file on the local disk was last modified.
|
||
name : String
[read-only]The name of the file on the local disk.
|
||
postData : String
POST parameters to submit with the upload or download.
|
||
size : Number
[read-only]The size of the file on the local disk, in bytes.
|
||
type : String
[read-only]The file type.
|
Properties inherited from class Object | |
---|---|
__proto__, __resolve, constructor, prototype |
Method | ||
---|---|---|
Creates a new FileReference object.
|
||
addListener(listener:Object):Void
Registers an object to receive notification when a FileReference event listener is invoked.
|
||
Displays a file-browsing dialog box in which the user can select a local file to upload.
|
||
cancel():Void
Cancels any ongoing upload or download operation on this FileReference object.
|
||
Displays a dialog box in which the user can download a file from a remote server.
|
||
Removes an object from the list of objects that receive event notification messages.
|
||
Starts the upload of a file selected by a user to a remote server.
|
Methods inherited from class Object | |
---|---|
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch |
Event | Summary | Defined by | ||
---|---|---|---|---|
onCancel = function(fileRef:FileReference) {}
| Invoked when the user dismisses the file-browsing dialog box. | FileReference | ||
onComplete = function(fileRef:FileReference) {}
| Invoked when the upload or download operation has successfully completed. | FileReference | ||
Invoked when an upload fails because of an HTTP error. | FileReference | |||
onIOError = function(fileRef:FileReference) {}
| Invoked when an input/output error occurs. | FileReference | ||
onOpen = function(fileRef:FileReference) {}
| Invoked when an upload or download operation starts. | FileReference | ||
Invoked periodically during the file upload or download operation. | FileReference | |||
Invoked when an upload or download fails because of a security error. | FileReference | |||
onSelect = function(fileRef:FileReference) {}
| Invoked when the user selects a file to upload or download from the file-browsing dialog box. | FileReference | ||
Invoked after data is received from the server after a successful upload. | FileReference |
creationDate | property |
creationDate:Date
[read-only]
Player version: | Flash Player 8 |
The creation date of the file on the local disk. If the FileReference object has not been populated, a call to get the value of this property returns null
.
public function get creationDate():Date
See also
import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("creationDate: " + file.creationDate); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
creator | property |
creator:String
[read-only]
Player version: | Flash Player 8 |
The Macintosh creator type of the file. In Windows, this property is null
. If the FileReference object has not been populated, a call to get the value of this property returns null
.
public function get creator():String
See also
import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("creator: " + file.creator); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
modificationDate | property |
modificationDate:Date
[read-only]
Player version: | Flash Player 8 |
The date that the file on the local disk was last modified. If the FileReference object has not been populated, a call to get the value of this property returns null
.
public function get modificationDate():Date
See also
modificationDate
of a file selected by the user. import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("modificationDate: " + file.modificationDate); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
name | property |
name:String
[read-only]
Player version: | Flash Player 8 |
The name of the file on the local disk. If the FileReference object has not been populated, a call to get the value of this property returns null
.
All the properties of a FileReference object are populated by calling browse()
. Unlike other FileReference properties, if you call download()
, the name
property is populated when onSelect
is invoked.
public function get name():String
See also
import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("name: " + file.name); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
postData | property |
public var postData:String
Player version: | Flash Player 8 |
POST parameters to submit with the upload or download.
See also
size | property |
size:Number
[read-only]
Player version: | Flash Player 8 |
The size of the file on the local disk, in bytes. If the FileReference object has not been populated, a call to get the value of this property returns null
.
public function get size():Number
See also
import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("size: " + file.size + " bytes"); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
type | property |
type:String
[read-only]
Player version: | Flash Player 8 |
The file type. In Windows, this property is the file extension. On the Macintosh, this property is the four-character file type. If the FileReference object has not been populated, a call to get the value of this property returns null
.
public function get type():String
See also
import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("type: " + file.type); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
FileReference | () | constructor |
public function FileReference()
Player version: | Flash Player 8 |
Creates a new FileReference object. When populated, a FileReference object represents a file on the user's local disk.
See also
import flash.net.FileReference; var listener:Object = new Object(); listener.onComplete = function(file:FileReference) { trace("onComplete : " + file.name); } var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.download(url, "FlashPlatform.pdf");
addListener | () | method |
public function addListener(listener:Object):Void
Player version: | Flash Player 8 |
Registers an object to receive notification when a FileReference event listener is invoked.
Parameterslistener:Object — An object that listens for a callback notification from the FileReference event listeners. |
import flash.net.FileReference; var listener:Object = new Object(); listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); } listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; fileRef.download(url, "FlashPlatform.pdf");
browse | () | method |
public function browse([typelist:Array]):Boolean
Player version: | Flash Player 8 |
Displays a file-browsing dialog box in which the user can select a local file to upload. The dialog box is native to the user's operating system. When you call this method and the user successfully selects a file, the properties of this FileReference object are populated with the properties of that file. Each subsequent time that FileReference.browse()
is called, the FileReference object's properties are reset to the file selected by the user in the dialog box.
You can pass an array of file types to determine which files the dialog box displays.
Only one browse()
session can be performed at a time (because only one dialog box can be displayed at a time).
In Flash Player 10 and later, you can call this method successfully only in response to a user event (for example, in an event handler for a mouse click or keypress event). Otherwise, calling this method results in Flash Player throwing an Error.
Because of new functionality added to Flash Player, when publishing to Flash Player 10, you can have only one of the following operations active at one time: FileReference.browse()
, FileReference.upload()
, FileReference.download()
. Otherwise, Flash Player throws a runtime error (code 2174). Use FileReference.cancel()
to stop an operation in progress. This restriction applies only to Flash Player 10. Previous versions of Flash Player are unaffected by this restriction on simultaneous multiple operations.
typelist:Array [optional] — An array of file types used to filter the files displayed in the dialog box. If you omit this parameter, all files are displayed. If you include this parameter, the array must contain one or more elements enclosed in curly braces { }. You can use one of two formats for the array:
The two formats are not interchangeable in a single The list of extensions is used to filter the files in Windows, depending on the file selected by the user. It is not actually displayed in the dialog box. To display the file types for users, you must list the file types in the description string as well as in the extension list. The description string is displayed in the dialog box in Windows. (It is not used on the Macintosh.) On the Macintosh, if you supply a list of Macintosh file types, that list is used to filter the files. If you don't supply a list of Macintosh file types, the list of Windows extensions is used. |
Boolean —
Returns true if the parameters are valid and the file-browsing dialog box is displayed. Returns false if the dialog box is not displayed, if another browse session is already in progress, or if you use the typelist parameter but fail to provide a description or extension string in any element in the array.
|
See also
import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("Opened " + file.name); } listener.onCancel = function(file:FileReference):Void { trace("User cancelled"); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
cancel | () | method |
public function cancel():Void
Player version: | Flash Player 8 |
Cancels any ongoing upload or download operation on this FileReference object.
import flash.net.FileReference; var listener:Object = new Object(); listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); if(bytesLoaded >= (bytesTotal / 2)) { file.cancel(); } } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; fileRef.download(url, "FlashPlatform.pdf");
download | () | method |
public function download(url:String, [defaultFileName:String]):Boolean
Player version: | Flash Player 8 |
Displays a dialog box in which the user can download a file from a remote server. Although Flash Player has no restriction on the size of files you can upload or download, the player officially supports uploads or downloads of up to 100 MB.
You cannot connect to commonly reserved ports. For a complete list of blocked ports, see the system.Security.loadPolicyFile()
entry.
This method first opens an operating system dialog box that asks the user to enter a filename and select a location on the local computer to save the file. When the user selects a location and confirms the download operation (for example, by clicking Save), the download from the remote server begins. Listeners receive events to indicate the progress, success, or failure of the download. To ascertain the status of the dialog box and the download operation after calling download()
, your ActionScript code must listen for events by using event listeners such as onCancel
, onOpen
, onProgress
, and onComplete
.
The FileReference.upload()
and FileReference.download()
functions are nonblocking. These functions return after they are called, before the file transmission is complete. In addition, if the FileReference object goes out of scope, any upload or download that has not yet been completed on that object is cancelled upon leaving the scope. So, be sure that your FileReference object will remain in scope for as long as the upload or download could be expected to continue.
When the file has successfully downloaded, the properties of the FileReference object are populated with the properties of the local file and the onComplete
listener is invoked.
Only one download()
session can be performed at a time (because only one dialog box can be displayed at a time).
In Flash Player 10 and later, you can call this method successfully only in response to a user event (for example, in an event handler for a mouse click or keypress event). Otherwise, calling this method results in Flash Player throwing an Error.
Because of new functionality added to Flash Player, when publishing to Flash Player 10, you can have only one of the following operations active at one time: FileReference.browse()
, FileReference.upload()
, FileReference.download()
. Otherwise, Flash Player throws a runtime error (code 2174). Use FileReference.cancel()
to stop an operation in progress. This restriction applies only to Flash Player 10. Previous versions of Flash Player are unaffected by this restriction on simultaneous multiple operations.
This method supports downloading of any file type, with either HTTP or HTTPS.
To send POST parameters to the server, set the value of FileReference.postData
to your parameters. You can also send GET parameters to the server with the download()
call by appending parameters to the URL, for the server script to parse.
When using this method, consider the Flash Player security model:
For more information related to security, see the following:
url:String — The URL of the file to download to the local computer. You can send GET parameters to the server with the download() call by appending parameters to the URL, for the server script to parse. For example:http://www.myserver.com/picture.jpg?userID=jdoe On some browsers, URL strings are limited in length. Lengths greater than 256 characters may fail on some browsers or servers. |
|
defaultFileName:String [optional] — The default filename displayed in the dialog box, for the file to be downloaded. This string cannot contain the following characters: / \ : * ? " < > | % If you omit this parameter, the filename of the remote URL is parsed out and used as the default. |
Boolean —
A value of true if the dialog box in which a user can select a file is displayed. If the dialog box is not displayed, the method returns false . The dialog box could fail to be displayed for any of the following reasons:
|
See also
download
method. Notice that there are listeners for all of the events. import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("onSelect: " + file.name); } listener.onCancel = function(file:FileReference):Void { trace("onCancel"); } listener.onOpen = function(file:FileReference):Void { trace("onOpen: " + file.name); } listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); } listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); } listener.onIOError = function(file:FileReference):Void { trace("onIOError: " + file.name); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; if(!fileRef.download(url, "FlashPlatform.pdf")) { trace("dialog box failed to open."); }
removeListener | () | method |
public function removeListener(listener:Object):Boolean
Player version: | Flash Player 8 |
Removes an object from the list of objects that receive event notification messages.
Parameterslistener:Object — An object that listens for a callback notification from the FileReference event listeners. |
Boolean —
Returns true if the object specified in the listener parameter was successfully removed. Otherwise, this method returns false .
|
removeListener
method. If a user cancels the download, the listener is removed so that it no longer receives events from that FileReference object. import flash.net.FileReference; var listener:Object = new Object(); listener.onCancel = function(file:FileReference):Void { trace(file.removeListener(this)); // true } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; fileRef.download(url, "FlashPlatform.pdf");
upload | () | method |
public function upload(url:String, uploadDataFieldName:String, testUpload:Boolean):Boolean
Player version: | Flash Player 8 |
Starts the upload of a file selected by a user to a remote server. Although Flash Player has no restriction on the size of files you can upload or download, the player officially supports uploads or downloads of up to 100 MB. You must call FileReference.browse()
or FileReferenceList.browse()
before calling this method.
You cannot connect to commonly reserved ports. For a complete list of blocked ports, see the system.Security.loadPolicyFile()
entry.
Listeners receive events to indicate the progress, success, or failure of the upload. Although you can use the FileReferenceList object to let users select multiple files to upload, you must upload the files one by one. To do so, iterate through the FileReferenceList.fileList
array of FileReference objects.
The FileReference.upload()
and FileReference.download()
functions are nonblocking. These functions return after they are called, before the file transmission is complete. In addition, if the FileReference object goes out of scope, any upload or download that has not yet been completed on that object is cancelled upon leaving the scope. So, be sure that your FileReference object will remain in scope for as long as the upload or download could be expected to continue.
Because of new functionality added to Flash Player, when publishing to Flash Player 10, you can have only one of the following operations active at one time: FileReference.browse()
, FileReference.upload()
, FileReference.download()
. Otherwise, Flash Player throws a runtime error (code 2174). Use FileReference.cancel()
to stop an operation in progress. This restriction applies only to Flash Player 10. Previous versions of Flash Player are unaffected by this restriction on simultaneous multiple operations.
The file is uploaded to the URL passed in the url
parameter. The URL must be a server script configured to accept uploads. Flash Player uploads files using the HTTP POST
method. The server script that handles the upload should expect a POST
request with the following elements:
Content-Type
element of multipart/form-data
Content-Disposition
element with a name
attribute set to "Filedata"
by default and a filename
attribute set to the name of the original fileHere is a sample POST
request:
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--
To send POST parameters to the server, set the value of FileReference.postData
to your parameters. You can send GET parameters to the server with the upload()
call by appending parameters to the URL.
If the file to be uploaded is bigger than approximately 10 KB, Windows Flash Player versions first send a test upload POST
with zero content prior to uploading the actual file in order to verify that the transmission is likely to be successful. The second POST
contains an actual file content. For smaller files, Flash Player does a single upload POST
with the file to be uploaded. The Macintosh players currently do not do test upload POST
s.
Note: If your server requires user authentication, only SWF files running in a browser—that is, using the browser plug-in or ActiveX control—can provide a dialog box to prompt the user for a user name and password for authentication, and only for downloads. For uploads that use the plug-in or ActiveX control, and for uploads and downloads that use the stand-alone or external player, the file transfer fails.
When using this method, consider the Flash Player security model:
For more information related to security, see the following:
url:String — The URL of the server script configured to handle upload through HTTP POST calls. The URL can be HTTP or, for secure uploads, HTTPS. |
|
uploadDataFieldName:String — The field name that precedes the file data in the upload POST. This parameter is supported in Flash Player 9.0.28.0 and later, only. The uploadDataFieldName value must be non-null and a non-empty String. By default, the value of uploadDataFieldName is "Filedata" : 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 — A setting to request a test file upload. If testUpload is true , then for files larger than 10 KB, Flash Player will attempt a test file upload POST with a Content-Length of 0. The purpose of the test upload is to check whether the actual file upload will be successful and whether server authentication, if required, will succeed. By default, testUpload is false . At this time, a test upload is done only for the Windows players. You can send GET parameters to the server with the On some browsers, URL strings are limited in length. Lengths greater than 256 characters may fail on some browsers or servers. |
Boolean —
A value of false in any of the following situations:
|
See also
upload()
method by first prompting the user to select a file to upload, then handling the onSelect
and onCancel
listeners, and finally handling the results of the actual file upload. import flash.net.FileReference; var allTypes:Array = new Array(); var imageTypes:Object = new Object(); imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)"; imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png"; allTypes.push(imageTypes); var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("onSelect: " + file.name); if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) { trace("Upload dialog failed to open."); } } listener.onCancel = function(file:FileReference):Void { trace("onCancel"); } listener.onOpen = function(file:FileReference):Void { trace("onOpen: " + file.name); } listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); } listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); } listener.onHTTPError = function(file:FileReference):Void { trace("onHTTPError: " + file.name); } listener.onIOError = function(file:FileReference):Void { trace("onIOError: " + file.name); } listener.onSecurityError = function(file:FileReference, errorString:String):Void { trace("onSecurityError: " + file.name + " errorString: " + errorString); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse(allTypes);
onCancel | event listener |
public onCancel = function(fileRef:FileReference) {}
Player version: | Flash Player 8 |
Invoked when the user dismisses the file-browsing dialog box. This dialog box is displayed when you call FileReference.browse()
, FileReferenceList.browse()
, or FileReference.download()
.
fileRef:FileReference — The FileReference object that initiated the operation. |
import flash.net.FileReference; var listener:Object = new Object(); listener.onCancel = function(file:FileReference):Void { trace("onCancel"); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; if(!fileRef.download(url, "FlashPlatform.pdf")) { trace("dialog box failed to open."); }
onComplete | event listener |
public onComplete = function(fileRef:FileReference) {}
Player version: | Flash Player 8 |
Invoked when the upload or download operation has successfully completed. Successful completion means that the entire file has been uploaded or downloaded. For file download, this event listener is invoked when Flash Player has downloaded the entire file to disk. For file upload, this event listener is invoked after the Flash Player has received an HTTP status code of 200 from the server receiving the transmission.
ParametersfileRef:FileReference — The FileReference object that initiated the operation. |
onComplete
event is triggered. import flash.net.FileReference; var listener:Object = new Object(); listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; fileRef.download(url, "FlashPlatform.pdf");
onHTTPError | event listener |
public onHTTPError = function(fileRef:FileReference, httpError:Number) {}
Player version: | Flash Player 8 |
Invoked when an upload fails because of an HTTP error.
Because of the way that Flash Player relies on the browser stack during file download, this error is not applicable for download failures. If a download fails because of an HTTP error, the error is reported as an I/O error.
ParametersfileRef:FileReference — The File Reference object that initiated the operation. |
|
httpError:Number — The HTTP error that caused this upload to fail. For example, an httpError of 404 indicates that a page is not found. HTTP error values can be found in sections 10.4 and 10.5 of the HTTP specification at ftp://ftp.isi.edu/in-notes/rfc2616.txt. |
onHttpError
. This listener is triggered only if the upload fails because of an HTTP error. import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("onSelect: " + file.name); if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) { trace("Upload dialog failed to open."); } } listener.onCancel = function(file:FileReference):Void { trace("onCancel"); } listener.onOpen = function(file:FileReference):Void { trace("onOpen: " + file.name); } listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); } listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); } listener.onHTTPError = function(file:FileReference):Void { trace("onHTTPError: " + file.name); } listener.onIOError = function(file:FileReference):Void { trace("onIOError: " + file.name); } listener.onSecurityError = function(file:FileReference, errorString:String):Void { trace("onSecurityError: " + file.name + " errorString: " + errorString); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
onIOError | event listener |
public onIOError = function(fileRef:FileReference) {}
Player version: | Flash Player 8 |
Invoked when an input/output error occurs.
This listener is invoked when the upload or download fails for any of the following reasons:
url
parameter in upload()
contains an invalid protocol. Valid protocols are HTTP and HTTPS.fileRef:FileReference — The FileReference object that initiated the operation. |
onIOError
event is triggered. For simplicity, none of the other event listeners are included in this example. import flash.net.FileReference; var listener:Object = new Object(); listener.onIOError = function(file:FileReference):Void { trace("onIOError"); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.download("http://www.adobe.com/NonExistentFile.pdf", "NonExistentFile.pdf");
onOpen | event listener |
public onOpen = function(fileRef:FileReference) {}
Player version: | Flash Player 8 |
Invoked when an upload or download operation starts.
ParametersfileRef:FileReference — The FileReference object that initiated the operation. |
onOpen
event is triggered. import flash.net.FileReference; var listener:Object = new Object(); listener.onOpen = function(file:FileReference):Void { trace("onOpen: " + file.name); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; fileRef.download(url, "FlashPlatform.pdf");
onProgress | event listener |
public onProgress = function(fileRef:FileReference, bytesLoaded:Number, bytesTotal:Number) {}
Player version: | Flash Player 8 |
Invoked periodically during the file upload or download operation. The onProgress
listener is invoked while the Flash Player transmits bytes to a server, and it is periodically invoked during the transmission, even if the transmission is ultimately not successful. To determine if and when the file transmission is successful and complete, use onComplete
.
In some cases, onProgress
listeners are not invoked; for example, if the file being transmitted is very small, or if the upload or download happens very quickly.
File upload progress cannot be determined on Macintosh platforms earlier than OS X 10.3. The onProgress
event is called during the upload operation, but the value of the bytesLoaded
parameter is -1, indicating that the progress cannot be determined.
fileRef:FileReference — The FileReference object that initiated the operation. |
|
bytesLoaded:Number — The number of bytes transmitted so far. |
|
bytesTotal:Number — The total size of the file to be transmitted, in bytes. If the size cannot be determined, the value is -1. |
onProgress
event listener. import flash.net.FileReference; var listener:Object = new Object(); listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress: " + file.name + " with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); var url:String = "http://www.adobe.com/platform/whitepapers/platform_overview.pdf"; fileRef.download(url, "FlashPlatform.pdf");
See also
onSecurityError | event listener |
public onSecurityError = function(fileRef:FileReference, errorString:String) {}
Player version: | Flash Player 8 |
Invoked when an upload or download fails because of a security error. The calling SWF file may have tried to access a SWF file outside its domain and does not have permission to do so. You can try to remedy this error by using a policy file.
ParametersfileRef:FileReference — The FileReference object that initiated the operation. |
|
errorString:String — Describes the error that caused onSecurityError to be called. The value is "securitySandboxError". |
onSecurityError
. The onSecurityError
listener is triggered only if the upload fails because of a security error. import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("onSelect: " + file.name); if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) { trace("Upload dialog failed to open."); } } listener.onCancel = function(file:FileReference):Void { trace("onCancel"); } listener.onOpen = function(file:FileReference):Void { trace("onOpen: " + file.name); } listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal); } listener.onComplete = function(file:FileReference):Void { trace("onComplete: " + file.name); } listener.onHTTPError = function(file:FileReference):Void { trace("onHTTPError: " + file.name); } listener.onIOError = function(file:FileReference):Void { trace("onIOError: " + file.name); } listener.onSecurityError = function(file:FileReference, errorString:String):Void { trace("onSecurityError: " + file.name + " errorString: " + errorString); } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
onSelect | event listener |
public onSelect = function(fileRef:FileReference) {}
Player version: | Flash Player 8 |
Invoked when the user selects a file to upload or download from the file-browsing dialog box. (This dialog box is displayed when you call FileReference.browse()
, FileReferenceList.browse()
, or FileReference.download()
.) When the user selects a file and confirms the operation (for example, by clicking OK), the properties of the FileReference object are populated.
The onSelect
listener works slightly differently depending on what method invokes it. When onSelect
is invoked after a browse()
call, Flash Player can read all of the FileReference object's properties, because the file selected by the user is on the local file system. When onSelect
is invoked after a download()
call, Flash Player can read only the name
property, because the file hasn't yet been downloaded to the local file system at the moment onSelect
is invoked. When the file has been downloaded and onComplete
invoked, then Flash Player can read all other properties of the FileReference object.
fileRef:FileReference — The FileReference object that initiated the operation. |
onSelect
event listener. import flash.net.FileReference; var listener:Object = new Object(); listener.onSelect = function(file:FileReference):Void { trace("onSelect: " + file.name); if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) { trace("Upload dialog failed to open."); } } var fileRef:FileReference = new FileReference(); fileRef.addListener(listener); fileRef.browse();
onUploadCompleteData | event listener |
public onUploadCompleteData = function(fileRef:FileReference, data:String) {}
Language version: | ActionScript 2.0 |
Player version: | Flash Player 9.0.28.0 |
Invoked after data is received from the server after a successful upload. This listener is not invoked if data is not returned from the server.
ParametersfileRef:FileReference — The FileReference object that initiated the operation. |
|
data:String — The raw data returned from the server in response to the successful upload. |