CFMU on complete attribute

Tags: CFMU,Flex
Word Count: 97

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.

Comments

#1 Posted By: johans Posted On: 4/15/09 12:58 AM
You could also consider using the Flex-Ajax bridge - FABridge. I found it pretty easy to implement. Under the section "About the Flex Ajax Bridge" here: http://livedocs.adobe.com/flex/3/html/help.html?co...

They list some of the advantages over using ExternalInterface
#2 Posted By: Mike Benner Posted On: 4/15/09 8:34 PM
File name being passed back is the original file name, correct? Is there away to get the unique name if CFFILE changed it?
#3 Posted By: Dan Vega Posted On: 4/15/09 9:20 PM |
Author Comment
There is no way to do this because the flash file does not know anything about the server. The file reference inside of the Flex application is what is passed to the JavaScript method.
#4 Posted By: johans Posted On: 4/16/09 12:24 AM
The service that uploads the file could always return the server file name and if it does not match the uploaded filename change that name in the list.
#5 Posted By: Dan Baughman Posted On: 8/18/10 8:29 AM
The latest version of flash player doesn't seem to fire the oncomplete any more, and the upload process hangs when it seems it should fire it.

This is a situation where it worked fine before where I have it in production sites. I return to these sites with the updated flash player and its not working any more.

Any suggestions?


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.