A foray into Flash

I recently had the opportunity to do a small enhancement to a web site. In particular a simple file upload “page” so that their logged in users can upload a pdf file to them. The site is a asp.net based site, so we could have used the asp file upload component, but it has no feedback while it’s waiting. So given the market share of Flash Vs. say JavaScript, Java, etc. We went with flash.

It was really actually a great project in that small and focused enough to be very manageable and I’d been looking for an excuse to play with it, but I’m not a graphics guy so I haven’t really had the opportunity to ever use it.

So, what I ended up doing was grabbing a file upload widget from FlahsDen ( http://flashden.net/item/upload-gadget/12202 ) It’s a fine widget and you get the source code. This particular component is made with the intent that it be embedded within a Flash based application. It’s quite configurable and had it up and working within a few hours of playing with it. Pretty good documentation to boot!

I embedded it within a very simple Flash data entry fields. The flow is, you fill out the form and the upload widget becomes usable and you upload the file. The page that accepts the incoming file and it’s accompanying form data then inserts the image as a binary blob in the DB and the values are inserted into the database as well.

When all is said and done it looks much like this (click for larger image):

flash-finished

The most difficult portion was writing the logic to control the date pickers, leap years and all. Actionscript 3 is essentially a strong type-able JavaScript. The syntax is slightly different but easy to get used to. It’s a little “sloppy” by which I mean undisciplined coding will lead to spaghetti code on the inside.

Once I got over the learning curve of Adobe Flash CS4, coding was nice. I used a programmatic event driven approach and it worked out really well. I was expecting a much more difficult time when I went to try sending the form data and the file upload which the purchased widget does via a FileReference. But it worked just like I wanted it to. Unfortunately the FileReference.Upload call throws away any http headers you may want to provide. I didn’t need that but ya never know.

Another interesting thing I found was that the combo box controls don’t initialize their selected index. I don’t know why I expected a fat 0 (zero) but it’s –1. I understand the ability to notice the default state’s value Vs.. a selected one, but for some reason that stuck with me.

In retrospect, the only thing I would have done differently was to make the form portion, straight asp.net dynamic html and disabled the flash uploader when the form wasn’t valid. Form values on the page are sent for the ride so I would never had to broker the user provided fields into the uploader to ride on it’s FileReference request.

At any rate, I’m left feeling intrigued and somewhat excited. I would like to work on some animation coding and perhaps pursue some more “real” custom flash based applications for clients.

I really wanted to hate it, and *hangs head in shame* kinda <3 it   😮

–Regards!