Adobe® Flex® 4 Language Reference
Show Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
flash.net 
FileReferenceList 
Packageflash.net
Classpublic class FileReferenceList
InheritanceFileReferenceList Inheritance EventDispatcher Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9

The FileReferenceList class provides a means to let users select one or more files for uploading. A FileReferenceList object represents a group of one or more local files on the user's disk as an array of FileReference objects. For detailed information and important considerations about FileReference objects and the FileReference class, which you use with FileReferenceList, see the FileReference class.

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, the fileList property of the FileReferenceList object is populated with an array of FileReference objects.
  • Call FileReference.upload() on each element in the fileList 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.

View the examples

See also



Public Properties
 PropertyDefined By
 Inheritedconstructor : 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
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined By
  
Creates a new FileReferenceList object.
FileReferenceList
 Inherited
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
  
browse(typeFilter:Array = null):Boolean
Displays a file-browsing dialog box that lets the user select one or more local files to upload.
FileReferenceList
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 Event Summary Defined By
 Inherited[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
 Inherited[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
Property Detail

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

See also

Constructor Detail

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.

See also

Method Detail

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.

Returns
Boolean — Returns true if the parameters are valid and the file-browsing dialog box opens.

Events
select:Event — Invoked when the user has successfully selected an item for upload from the dialog box.
 
cancel:Event — 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.

See also

Event Detail

cancel

Event
Event Object Type: 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.)

The Event.CANCEL constant defines the value of the type property of a cancel event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetA reference to the object on which the operation is canceled.

See also

select

Event  
Event Object Type: 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.

The Event.SELECT constant defines the value of the type property of a select event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object on which an item has been selected.

See also

FileReferenceListExample.as

The following example shows how you can use events to manage the upload of multiple files. The CustomFileReferenceList class extends FileReferenceList and includes a 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());
    }
}