Package | flash.net |
Class | public class FileReferenceList |
Inheritance | FileReferenceList EventDispatcher Object |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
To work with the FileReferenceList class:
- Instantiate the class:
var myFileRef = new FileReferenceList();
- Call the
FileReferenceList.browse()
method, which opens a dialog box that lets the user select one or more files for upload:myFileRef.browse();
- After the
browse()
method is called successfully, thefileList
property of the FileReferenceList object is populated with an array of FileReference objects. - Call
FileReference.upload()
on each element in thefileList
array.
The FileReferenceList class includes a browse()
method and a
fileList
property for working with multiple files. While a call to FileReferenceList.browse()
is executing, SWF file playback pauses in stand-alone and external versions of Flash Player
and in AIR for Linux and Mac OS X 10.1 and earlier.
Related API Elements
Property | Defined By | ||
---|---|---|---|
constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | ||
fileList : Array [read-only]
An array of FileReference objects. | FileReferenceList |
Method | Defined By | ||
---|---|---|---|
Creates a new FileReferenceList object. | FileReferenceList | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | ||
Displays a file-browsing dialog box that lets the
user select one or more local files to upload. | FileReferenceList | ||
Dispatches an event into the event flow. | EventDispatcher | ||
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Removes a listener from the EventDispatcher object. | EventDispatcher | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Returns the primitive value of the specified object. | Object | ||
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Event | Summary | Defined By | ||
---|---|---|---|---|
[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher | |||
Dispatched when the user dismisses the file-browsing dialog box. | FileReferenceList | |||
[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher | |||
Dispatched when the user selects one or more files to upload from the file-browsing dialog box. | FileReferenceList |
fileList | property |
fileList:Array
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
An array of FileReference
objects.
When the FileReferenceList.browse()
method is called and the user
has selected one or more files from the dialog box that the browse()
method opens,
this property is populated with an array of FileReference objects,
each of which represents the files the user selected.
You can then use this array to upload each file with the FileReference.upload()
method.
You must upload one file at a time.
The fileList
property is populated anew each time browse() is called on
that FileReferenceList object.
The properties of FileReference
objects are described
in the FileReference class documentation.
Implementation
public function get fileList():Array
Learn more
Related API Elements
FileReferenceList | () | Constructor |
public function FileReferenceList()
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Creates a new FileReferenceList object. A FileReferenceList object contains nothing
until you call the browse()
method on it and the user selects one or more files.
When you call browse()
on the
FileReference object, the fileList
property of the object is populated
with an array of FileReference
objects.
Related API Elements
browse | () | method |
public function browse(typeFilter:Array = null):Boolean
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Displays a file-browsing dialog box that lets the user select one or more local files to upload. The dialog box is native to the user's operating system.
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.
When you call this method and the user successfully selects files,
the fileList
property of this FileReferenceList object is populated with
an array of FileReference objects, one for each file that the user selects.
Each subsequent time that the FileReferenceList.browse() method is called, the
FileReferenceList.fileList
property is reset to the file(s) that the
user selects in the dialog box.
Using the typeFilter
parameter, you can determine which files
the dialog box displays.
Only one FileReference.browse()
, FileReference.download()
,
or FileReferenceList.browse()
session can be performed at a time
on a FileReferenceList object
(because only one dialog box can be opened at a time).
Parameters
typeFilter:Array (default = null ) — An array of FileFilter instances used to filter the files that are
displayed in the dialog box. If you omit this parameter, all files are displayed.
For more information, see the FileFilter class.
|
Boolean — Returns true if the parameters are valid and the file-browsing dialog box
opens.
|
Events
select: — Invoked when the user has successfully selected an item for upload from the dialog box.
| |
cancel: — Invoked when the user dismisses the dialog box by clicking Cancel or by closing it.
|
Throws
IllegalOperationError — Thrown for the following reasons: 1) Another FileReference
or FileReferenceList browse session is in progress; only one file browsing session
may be performed at a time. 2) A setting in the user's mms.cfg file prohibits this operation.
| |
ArgumentError — If the typeFilter array does not contain correctly formatted
FileFilter objects, an exception is thrown. For details on correct filter formatting,
see the FileFilter documentation.
| |
Error — If the method is not called in response to a user action, such as a mouse
event or keypress event.
|
Learn more
Related API Elements
cancel | Event |
flash.events.Event
property Event.type =
flash.events.Event.CANCEL
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched when the user dismisses the file-browsing dialog box.
(This dialog box opens
when you call the FileReferenceList.browse()
,
FileReference.browse()
, or FileReference.download()
methods.)
Event.CANCEL
constant defines the value of the type
property of a cancel
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | A reference to the object on which the operation is canceled. |
Related API Elements
select | Event |
flash.events.Event
property Event.type =
flash.events.Event.SELECT
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched when the user selects one or more files to upload from the file-browsing dialog box.
(This dialog box opens
when you call the FileReferenceList.browse()
,
FileReference.browse()
, or FileReference.download()
methods.)
When the user selects a file and confirms the operation (for example, by clicking Save),
the FileReferenceList
object is populated with FileReference objects
that represent the files that the user selects.
Event.SELECT
constant defines the value of the type
property of a select
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The object on which an item has been selected. |
Related API Elements
complete
event,
which is dispatched
when each individual file in the FileReferenceList object is uploaded. The LIST_COMPLETE
event in the FileReferenceListExample class is dispatched when all the files in the FileReferenceList
object have been uploaded.
To run this example, place a script that is written to accept a file upload at http://www.[yourDomain].com/yourUploadHandlerScript.cfm. Based on the location of your SWF file and where you are uploading files to, you also might need to compile the SWF file with Local Playback Security set to Access Network Only or update Flash® Player security settings to allow this file network access. If your upload server is remote and you run this example from your desktop computer, your server must have a crossdomain.xml file.
package { import flash.display.Sprite; import flash.events.*; import flash.net.FileReference; import flash.net.FileReferenceList; public class FileReferenceListExample extends Sprite { public static var LIST_COMPLETE:String = "listComplete"; public function FileReferenceListExample() { initiateFileUpload(); } private function initiateFileUpload():void { var fileRef:CustomFileReferenceList = new CustomFileReferenceList(); fileRef.addEventListener(FileReferenceListExample.LIST_COMPLETE, listCompleteHandler); fileRef.browse(fileRef.getTypes()); } private function listCompleteHandler(event:Event):void { trace("listCompleteHandler"); } } } import flash.events.*; import flash.net.FileReference; import flash.net.FileReferenceList; import flash.net.FileFilter; import flash.net.URLRequest; class CustomFileReferenceList extends FileReferenceList { private var uploadURL:URLRequest; private var pendingFiles:Array; public function CustomFileReferenceList() { uploadURL = new URLRequest(); uploadURL.url = "http://www.[yourDomain].com/yourUploadHandlerScript.cfm"; initializeListListeners(); } private function initializeListListeners():void { addEventListener(Event.SELECT, selectHandler); addEventListener(Event.CANCEL, cancelHandler); } public function getTypes():Array { var allTypes:Array = new Array(); allTypes.push(getImageTypeFilter()); allTypes.push(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 doOnComplete():void { var event:Event = new Event(FileReferenceListExample.LIST_COMPLETE); dispatchEvent(event); } private function addPendingFile(file:FileReference):void { trace("addPendingFile: name=" + file.name); pendingFiles.push(file); file.addEventListener(Event.OPEN, openHandler); file.addEventListener(Event.COMPLETE, completeHandler); file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); file.addEventListener(ProgressEvent.PROGRESS, progressHandler); file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); file.upload(uploadURL); } private function removePendingFile(file:FileReference):void { for (var i:uint; i < pendingFiles.length; i++) { if (pendingFiles[i].name == file.name) { pendingFiles.splice(i, 1); if (pendingFiles.length == 0) { doOnComplete(); } return; } } } private function selectHandler(event:Event):void { trace("selectHandler: " + fileList.length + " files"); pendingFiles = new Array(); var file:FileReference; for (var i:uint = 0; i < fileList.length; i++) { file = FileReference(fileList[i]); addPendingFile(file); } } private function cancelHandler(event:Event):void { var file:FileReference = FileReference(event.target); trace("cancelHandler: name=" + file.name); } private function openHandler(event:Event):void { var file:FileReference = FileReference(event.target); trace("openHandler: name=" + file.name); } 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 { var file:FileReference = FileReference(event.target); trace("completeHandler: name=" + file.name); removePendingFile(file); } private function httpErrorHandler(event:Event):void { var file:FileReference = FileReference(event.target); trace("httpErrorHandler: name=" + file.name); } private function ioErrorHandler(event:Event):void { var file:FileReference = FileReference(event.target); trace("ioErrorHandler: name=" + file.name); } private function securityErrorHandler(event:Event):void { var file:FileReference = FileReference(event.target); trace("securityErrorHandler: name=" + file.name + " event=" + event.toString()); } }
Thu Dec 6 2018, 01:12 PM -08:00