CFMU on complete attribute
The next feature of CFMU I want to go over is the on complete attribute. This allows you to define a JavaScript method name that will be called after the files have been uploaded. This will run every time you upload a single file or a batch of files. In addition to calling the method of your choice it will also pass an array of the files that were uploaded and will contain the following info about each file.
- creationDate
- creator
- modificationDate
- name
- size
- type
Now that you know what you can do let's take a look at a basic example of how this works. All you need to do is provide the name of the javascript method and your file list will be passed. In this example we are just logging the file list to the Firebug console. If your not using Firebug please stop reading this and go install it!
This was pretty cool on the Flex end because I was not quite sure how to do this so I asked around and got my answer. The flash.external.ExternalInterface defined by the live docs.
The ExternalInterface class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container– for example, an HTML page with JavaScript. Adobe recommends using ExternalInterface for all JavaScript-ActionScript communication.
The following method in my code is called when a file upload has been completed. Every time this method is called we are checking to see what the length of the _files array is. When its empty we are checking to see if the user provided the on complete attribute and if they did we call our method call on the static class flash.external.ExternalInterface.
Tomorrow I will post an advanced version of this sprinkled with some jQuery but until then If you have any questions don't hesitate to ask.
