One of the most exciting new features of Flash is the capability to download and upload files directly from your SWF. Flash accomplishes this by means of the FileReference object.
The FileReference object allows you to browse for files with the browse() method. You can even tell Flash what types of files you want the end user to be able to select. And when a user selects a file, the FileReference will have these available properties:
Following is an example that will allow you to select a file and then display all the information in the Output panel.
This code does quite a few things. First, it imports the necessary class file for the FileReference object. Then it creates a generic object to use as a listener for the onSelect event that is triggered when a user selects a file and clicks Open. Then we create the actual event callback for the listener object. Next the listener object is added to our FileReference. And finally, we create the event for the Button component, so that when the button is clicked, the File Browse window will appear.
Test this movie, and when you select a file and click Open, you should see some information about the file in the Output panel, as shown in Figure 1.15.
Figure 1.15. One of the best new features in Flash is the capability to select files for upload and download.
If you want to see the FileReference object working with a server-side script to actually be able to upload images, check out Chapter 22, "PHP and Flash."