In my CFMU project I am using the ExternalInterface class. This class allows your application to communicate with the flash players container, in this case the ColdFusion template and JavaScript. I originally was giving users the ability to define a JS function that would be called when all of the files were uploaded. I had a couple people email telling me that it was just not working how it should be. When they were uploaded files the JavaScript method was being called right away while the file uploads were still in progress.

As soon as I heard this I realized what I had done. Let's take a look at the following code. When a user selects some files for upload and clicks on the upload button the following method is called. The variable _files is an array collection that holds a list of File references. The File Reference class has a method upload that is used to push the file to a remote server. You will also notice that I add some event listeners to each file. This lets us monitor the progress of the upload and is important for the feature we are working. The problem here is that I am calling the external interface method after each file is sent for upload. This does not mean that the file has actually been uploaded, just that Flash has done it's part. So what would happen is the list of files would immediately show up right after the user clicked upload and this is not what we want.

As I said before we added some event listeners to each of those files. The Event.COMPLETE event will let us know when a file has been uploaded to the remote server. All this method did before was remove the file from the array and in turn remove it from our data grid since our data grids data provider was that array collection. If we go a head and add our external interface call here we will get the desired solution we are looking for.

I played around with the idea of a couple different implementations but I think in the end this works best. After each file is uploaded your JavaScript method will be called and it will be passed the file reference. Here is example of how you could use this feature to write the files to screen as they are uploaded. If you still want the ability to have a list of all the files uploaded you could simply create an array and add to that as the file references come in.

I hope this helps out everyone and thanks to the couple users who pinged me about this. Please let me know if this is working as expected. I pushed a new version to the RIAForge project page this morning.