Friday, March 28, 2008

Adobe Flex - Flash Programming for Programmers!

One of the features that I was really excited about implementing in Ringlight was a Flash-based media player for browsing photos, videos, and audio files. I like the idea of being able to view all of my files from any computer with a web browser without having to download them first.

Unfortunately, Flash programming is not the most natural occupation for me. I find the concept of laying your code out on a timeline which trudges ever forward, causing variables to go in and out of scope based on the ticking of a clock... well, I don't like it very much. I don't particularly appreciate the Flash IDE or the fact that Flash source is in a binary file either. I don't mean to malign the art of the Flash programmer. I know you all have heroically found workarounds to all of these inconveniences and I salute your dedication. It's just not my cup of tea.

However, now we have Adobe's Flex. It fixes most of my problems with Flash programming because it's Flash programming designed for programmers. The entire source for a Flex project is in an XML file. While I am not one to jump on the XML-solves-everything wagon, it does mean that you can edit for Flash applications in a text editor, check them into source control, and cut-and-paste whole projects to your blogs and chats and such.

Additionally, the compiler is free and cross-platform. This means you can compile your Flash apps right on your server. No more compiling on your desktop, uploading to the server, testing, and repeat. There's even an Apache module which will automatically detect changes in the source and recompile apps for you on demand. Sweet.

This is not to say that Flex is without problems. Flex coding can be as frustrating as Flash programming sometimes. I recently had a terrible time trying to follow online tutorials for making a Flex image browser. They all suggested using the Loader class, but it had some issues with image scaling. However, the suggested workaround for image scaling involves accessing the raw bitmap data of the image. This operation is unfortunately blocked by Adobe's inane and pointless security model, which requires that to access the raw bitmap data of an image the site hosting the image must authorize it in their crossdomain.xml file. So you are totally free to write a Flex image gallery for Flickr photos, but if you want to scale them then that's not allowed! The workaround is to just use the Image class instead of Loader. You don't get the right events to have a fancy loading animation this way, but at least it works.

Check out my Flex image loader example code. It's not finished as the buttons don't work yet, but it does load images just fine.

All in all I'd say that Flex is a breath of fresh air in the world of Flash programming. If you're a programmer then I'd recommend that you try it out.