Export Layers to SWF with JSFL

jsflIt's embarrassing but until the other week I hadn't a reason to do anything (beyond tinkering) with JSFL. JSFL can be especially useful for simplifying or automating tasks in the Flash IDE and that isn't breaking news. I think I understand why I haven't been using JSFL too much until recently. The major problem I discovered is the documentation is very poor, if you search JSFL you get exactly diddly squat on how to use JSFL. And alas Googling JSFL aint much better with the term "JSFL Reference" the only adobe link is this one. Considering this help reference is 5 years old doesn't inflate confidence in learning the latest and greatest JSFL has to offer - this is really pathetic Adobe. If someone can find an official decent resource on JSFL it would be appreciated, SURELY that isn't it :) So despite not being able to find a great JSFL reference Eventually I was referred to this great JSFL reference. The JSFL script I needed to write was really quite basic and for Actionscript developers writing JSFL it is very familiar territory so I was somehow blindly confident.

So I will describe the usefulness of this JSFL script by first explaining the task or problem at hand it solved for me and hopefully you find it useful also.

The Problem

I had a rather complex vector map (12 MB) in a SWF. Embedding the whole map would be obviously be a BAD idea for loading times but fortunately only very small portions of this map had to be used at any time. Though the suker punch to this idea is that the map isn't grouped to these portions - sigh.

The Solution

So I started with some unavoidable and rather laborious instance naming grinding which I did within Flash. Once I had completed this I had literally 100's of Movieclips associated to Classes that needed to be published and when I hit this I  realised - JSFL I love you! So I distributed these MovieClips to layers then ran this script and viola all the layers are published as swfs using the layer name as the published SWF name - ba da boom ching :)

The way this script works is that publishes any layer that isn't a folder or a guide on the main timeline. Then sets all the layers to guides, then loops through the layers desired to be outputted to SWF then changes them to a normal layer so that only this layer is the only one in the published SWF. Once the publish loop is completed all layers are then set back to their original states.

Rather simple I thought and a huge time saver for mindless SWF publishing. To run this JSFL simply double click it or drag it onto Flash then you will be prompted to select the output directory. Then sit back, relax or even take the evening off and tell your project manager you're hard at work!

You can view the source or download this script here - get it while it's hot!