Accessibility

Table of Contents

Uploading files to a server from an Adobe AIR application

The FileReference and FileReferenceList classes

The FileReference and FileReferenceList classes provide an interface between the user's computer and a remote server by which file uploads and downloads can occur.

The difference between the two classes is that FileReference is used for the uploading of a single file, whereas the FileReferenceList allows the user to select multiple files for simultaneous uploads.

File uploading is not new to ActionScript 3.0. The classes showed up in ActionScript 2.0 with the release of Flash 8 and were met with much appreciation from the Flash development community. Prior to this, any file uploads employed within a Flash based application were handled through external calls to an HTML-based augmentation to the application using the traditional HTML <input type="file"/> browse interface.

A very simple example of the FileReference class with the purpose of demonstrating the opening of the operating system browse dialog box (which is the same experience encountered when using the <input type="file"/> method in an HTML application) is demonstrated below:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="/2006/mxml" layout="absolute" applicationComplete="startApplication();">
   <mx:Script>
       <![CDATA[
           private var fileReference:FileReference = new FileReference();
           private function startApplication():void {
               fileReference.browse();
           }
       ]]>
   </mx:Script>
</mx:WindowedApplication>

If you make a slight adjustment to the code above, the operatings system browse dialog box will enable the user to select multiple files for upload. All you have to do is change the following:

private var fileReference:FileReference = new FileReference();

to:

private var fileReference:FileReferenceList = new FileReferenceList();