Upload Multiple Files with ActionScript 3

Upload Multiple Files with ActionScript 3

In this little tutorial we will show you how you can upload one or more file(s) using the FileReferenceList in Flash CS3.

We will use amfphp to upload the image to a location on our server , so it can be tested locally … but the upload.php script can also be on any online webhosting.

We will begin by declaring a new FileReferenceList object … after that we will set the object to show the browse window to select the files that need to be uploaded.

We also need to listen for the select event , this event is triggerd whenever enter is pressed, or the select button is clicked from the upload component.

Creating a new FileReferenceList

Creating a new FileReferenceList

Now we specify the upload destination location, hereby i use a php file that uploads the file from the uploadReferenceList to the location specified in the php file (a directory on our amfphp server on in other cases a online location).

Upload Script PHP

Upload Script PHP

We now specify the location of this file to the URLRequest.

Upload Script Location

Upload Script Location

Now , this is what the fileSelectHandler looks like, we will loop through the fileList of the FileReference (so all the files we selected for upload), and push them into a custom function uploadSingleFile….

Select Handler

Select Handler

Here we just upload the file that was passed into the function to the php file on our amfphp server …

We also add a complete handler , so can trigger an action for the upload complete event.

Upload Single File

Upload Single File

Upload Complete Handler

Upload Complete Handler


Also interesting reads:
  1. Singleton Design Pattern Actionscript 3
  2. Object-Orientated Programming in Flash Lite 2.x

About the Author

Daan is a Creative-Geek with passion for Adobe Flash , Flex and Air. He loves learning and sharing new techniques! Follow him on Twitter to keep up to date with the Creative-Geeks blog and other subjects. Contact him on e-mail : info[at]creative-geeks.com