AS3 Upload: File Filtering
The FileFilter class is used to indicate what files on the user’s system are shown in the file-browsing dialog box that is displayed when FileReference.browse() or FileReferenceList.browse() is called.
The FileFilter instances can also be passed to a browse() function. If you use a FileFilter instance, extensions and file types that aren’t specified in the FileFilter instance are filtered out; that is, they are not available to the user to select for uploading. If no FileFilter object is passed to browse(), all files are shown in the dialog box.
You can use FileFilter instances in one of two ways:
- A description with Windows file extensions only
- A description with Windows file extensions and Macintosh file types
The two formats are not interchangeable within a single browse() call. You must use one or the other.
You can pass one or more FileFilter instances to FileReference.browse() or FileReferenceList.browse(). The following examples show different ways to create and pass FileFilter instances to a browse() call (for Windows only). The first example creates FileFilter instances outside of the browse() call:
var imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.gif;*.png");
var docFilter:FileFilter = new FileFilter("Documents", "*.pdf;*.doc;*.txt");
var myFileReference:FileReference = new FileReference();
myFileReference.browse([imagesFilter, docFilter]);
The second example creates FileFilter instances within the browse() call:
myFileReference.browse( [ new FileFilter("Images", "*.jpg;*.gif;*.png"), new FileFilter("Flash Movies", "*.swf") ] );
The list of extensions in the FileFilter.extension property 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 Mac, if you supply a list of file types, that list is used to filter the files. If not, the list of Windows extensions is used.
Please consider to buying me a coffee.






I must admid that I’m a noob with some aspects of AS3 and Flex Builder. Searching around for “actionscript 3 file browser” and “actionscript 3 parse text file”, there is a decent amount out there, but from what I’ve found, very little of it works. Your information works great. It brings up the file browser and allows me to select only the file types I specify. I put in an event listener which triggers after the user selects the file but I’m not sure how to reference the file after it’s been imported. Can you assist? Basically, I have a plaintext file (.mtf) which I need to parse for my own purposes. I just don’t know the syntax of how to get at what I just loaded.
Hi Charles,
Ofcourse i can assist. If i get this right this is what you want to do: Prompt the user with a dialog box for a file to upload / load, read this file in, parse it and do something with the results?
Let me know so i can help you further,
Cheers,
Sid