Real World Flex/ColdFusion: Part 11
This will be the last post in this series. While I will continue to add features to this project and share the details with you, I wanted to find a clear line where I could close this series. The last feature is probably the most important. What good is a file manager if you can't upload new files. This post will cover the upload component.
First we are going to create a new file components/RocketUploader. The component we are creating is going to be based on a Title Window because we are going to launch the uploader as a popup from our application. The layout of the component is pretty simple. I know we talked about layouts at the beginning of this series and I am doing the exact opposite of what I preached but I just like the look and feel of the panel component here. In the panel we have some buttons, a data grid to display the files and progress bar to show file upload progress.
To upload a file you will click on the browse button, select some files and click the upload button. To present the user with a browse dialog box we will work with the FileReference class. When the user selects a file or files the onSelectFile method is called. For each file that was selected we will loop through and add it to our _files array.
When the user clicks the upload button we are going to call the on upload method. For each file in the list we are going to push the file to our File Manager component method upload. The important thing to notice here is that one of the events we can listen for is the complete event. In our complete event handler we are going to remove the item from the data grid and dispatch a new custom event to our application. The custom event basically tells our application that we need to update the file listing and we will push the path along with the event.
Back in our main application we need to set a click handler for the upload button. In the openUploader method we are creating an instance of our RocketUploader and adding it to the screen using the popup manager. Another cool little lesson here is figuring out what to set the width and height of our uploader. Usually you can set a percentage width but here what don't know what width is so this won't work. What we want to do is figure out what the stage size is and take about 60% of that.
With that I think we are going to end this series. You can check out a screen shot below of the upload component in action. I will posting more updates to the application in the near future but for now you can grab the code from svn over at http://rocketfm.riaforge.org. Please feel free to contact me with any questions or problems that you run into.

