Chapter 23. File Management

Introduction

Prior to Version 8, the Flash Player did not support any mechanism for allowing the user to browse her computer for files. Furthermore, Flash Player didn’t have a mechanism for uploading or downloading files, either. As such, most web applications used HTML-based solutions for uploading and downloading files. Flash-based applications not deployed on the Web often had to use customized solutions for uploading and downloading files. Flash Player 8 and higher now supports the new APIs, which greatly simplify file I/O by allowing Flash Player to browse a user’s system for files to upload and download.

Flash Player allows users to browse to files on their local disks and upload and download files using the FileReference and FileReferenceList classes. This chapter discusses the details of working with those APIs.

Downloading Files

Problem

You want to let users download files to their computer.

Solution

Use the download() method of a FileReference object.

Discussion

The flash.net.FileReference class defines a download() method that allows users to download a file from a URL to their computers. When Flash Player calls the download() method, it attempts to open a dialog box, titled “Select location for download.” This dialog box allows users to use a standard operating system dialog to browse their local disks for a location to which they want to save files.

The first step before calling the download() method is to construct a FileReference object, as follows: ...

Get ActionScript 3.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.