Better Web Development, part 4: Flash
Tuesday, February 28th, 2006In the last eight years, I have made lots of advances with my web development. I am always learning new methods, new tools, and new strategies on the path to intelligent web development. These are tips I’ve learned from my progress so far.
(Inspired by the Graphic Push article “The Path to Intelligent HTML“)
Flash
Single Files - NO
Working with Flash, it is very easy (and tempting!) to put everything into a single file. As long as your flash file is neatly organized, this shouldn’t be a problem, right? Not quite. It’s very easy to create gigantic files that not only take forever for the user download, but which take forever to compile, wasting precious development time. I first started dividing my flash movies into multiple files in an attempt to solve bandwidth problems for the end-user. But it wasn’t until Flash introduced the ability to import external JPGs and MP3s instead of just other SWF files that I really started loving this technique.
My favorite example is with galleries or slideshows. These can include dozens or even hundreds of images, yet since the point of these movies is to show off the images, lowering the resolution really just defeats the purpose. This is an easy recipe for an enormous flash file! So, to solve this problem, I create the initial interface in flash, but load the images from external files - each with their own loader bar if necessary. This splits up the download nicely for the user, and the sky’s the limit for the number of images you can use with this technique.
External Definitions - YES
Traditionally with Flash, it has been possible to load text files full of variable definitions. I used this to its fullest potential, but it was… well, clunky. Importing single values was fine, but importing a collection of values was done by defining “value_01″, “value_02″, “value_03″, etc. After the variables were loaded, you would run a function to move all of these individual variables into more accessible structures like Objects or Arrays (or arrays of objects!). There had to be a better way. And then Macromedia gave it to us: XML!
Now, if I want to include variables in external files, I can use an XML document. I particulary like to use XML defined values when I am creating galleries and slideshows. I mentioned above that I like to import the external JPGs at runtime. I also like to define what images are used and the order in which they’re used with XML files. This is one of the best ways to speed up project updates! Say, for instance, a client wants to rearrange the order of slides in a slideshow. If you made the movie the traditional way, you’ll have to open up Flash, move clusters of frames around, and recompile. But by using external JPGs defined in an XML document, all you have to do is open up the XML in a text editor and cut and paste the nodes that need rearranging. Easy!
Another favorite use of external XML is for link definitions. If a client needs to change the URLs of external links within the movie, all it takes is a quick XML update. I also use this technique for menus, image sequences, and content.
Reusable Scripts and Components - YES
After developing in flash for a while, you will have accumulated a library of functions, objects, and animations that you frequently reuse in other projects. Scripts can be included into a Flash document with the “#include” directive, which can help you avoid repetitive changes. For instance, say you have a button that triggers a function on the rollOver event, and this button is animated over many keyframes. Normally, if you wanted to change the rollOver event for that button over the entire animation, you would have to edit the button’s actions at every keyframe. But if you defined the button’s actions in an external script, and “#include” that script at every keyframe, you simply edit the external script once to change the button’s behavior for the entire animation!
Graphics, buttons, and movieclips can be reused as well by being saved to an external library. You can open the external library, and drag and drop these items into your current document. But it gets even better with components! In Flash, components are a nice method of packing your most powerful custom objects in a way that makes them even more accessible - just look for your custom elements in the Components panel! You can even ‘run’ them inside the Flash development environment, so you can see how they will look in the final compiled output! (this is called “Live Preview”) Components can be simple, or can involve complicated, programmatically-rendered designs. They’re the ultimate in resusability and, if done right, in scalability as well.
