One of our current projects has over 50 FLAs, all of which need to be compiled, and organized into the proper directories on a regular basis. I got bored of trying to remember what had to be compiled, and doing it all manually, so I wrote a simple JSFL script that compiles and moves them all for me (it also does other interesting stuff, like update import linkage URLs depending on whether I'm doing a production or dev build, but more on that later). It also generates a handy-dandy log of the process.
I thought this might be useful for other people, so I spent a bit of time making it more generic and easy to use. Here are some instructions on how to use it - you can download the script and a simple usage demo at the end of this post.
Usage:
To use this script, you must set up a compile schema file for your project. This is just a simple text file in the format:
FLAPath SWFPath PublishProfileName
FLAPath SWFPath PublishProfileName
Each line represents a single compile action, and is comprised of the path to the FLA (in URI format, relative to the location of the compile schema file) followed by a single tab, then the path that you want the SWF moved to (again, URI relative to compile schema), and finally another tab character followed by the name of the publishing profile you wish to use. Both the SWF path and publish profile are optional - if the SWF path is omitted, it will simply compile the FLA and leave the SWF in its default location, if the publish profile is omitted it will just use the default profile. A finished schema might look like:
core.fla swfs/myCore.swf testProfile
assets/asset1.fla swfs/assets/one.swf
assets/asset2.fla swfs/assets/two.swf
The first line would tell the compile script to compile core.fla in the same directory as the compile schema using the testProfile publishing profile, then move the swf into the swfs directory and rename it myCore.swf.
Once the schema is set up, you simply run the command (Command menu: Run command... or by adding it to your commands list), select your schema in the file dialog that opens and grab a coffee. The command will compile your files according to your schema and generate a lovely verbose log file called "compile_log.txt" in the same directory as your schema.
Limitations:
There are, unfortunately, a couple of limitations - perhaps some JSFL gurus have some work-arounds to these (if so, please post in the comments):
1) Doesn't log publish errors - there doesn't seem to be any way in JSFL to access the contents of the output panel or any errors output by a publish call. UPDATE: Fixed - will now log publish errors. Thanks to Keith Peters for the heads up on fl.outputPanel.save().
2) Doesn't launch your main swf - I wanted to make it automatically launch the first swf generated when it finished compiling, but I can't see a way of making Flash do this in JSFL.
3) As with any JSFL that uses the FileAPI, I would recommend caution in using this script - I took a lot of care in making this safe to use (and have been using it on my system), but there are no guarantees that it won't thrash something.
Download
You can download the JSFL file, and a simple demo of it in use by clicking here. Be sure to read the disclaimer in the JSFL source before using. Hope this helps someone.

Comments (22)
As for limitation #1, you can use fl.outputPanel.save();
As for #2, you can say:
Posted by: Keith Peters at August 19, 2004 10:51 AMfl.openDocument(fileURI);
fl.getDocumentDOM().testMovie(); // or publish()
URL: http://www.bit-101.com
Thanks Keith,
#1 sounds like it will work... #2 won't work how I want it, because I'd like to be able to move the swf before I open it (had already considered using testMovie instead of publish).
Posted by: Grant Skinner at August 19, 2004 11:02 AMURL: http://gskinner.com/
#2: you can open swf-files by using fl.openScript().
there is no hint in the jsfl-docs about that but it works.
example:
fl.openScript("file:///c|/test.swf")
Martin
Posted by: Martin Eder at August 20, 2004 11:16 AMURL:
Nice. Added this in and uploaded a new version - thanks Martin.
Posted by: Grant Skinner at August 20, 2004 03:03 PMURL: http://gskinner.com/
nice work ! thanx !
Posted by: Francis Bourre at August 22, 2004 02:36 PMURL: http://www.tweenpix.net
thanks a lot,
Posted by: Clément Hussenot at August 25, 2004 03:16 PMshare your work is cool !
URL:
Grant,
Posted by: eyezberg at August 29, 2004 02:41 AMthanks for this, I'll post about this on my site.
URL: http://www.eyezberg.com
To help generate the text file for batch compiling you can make a "filelist.bat" file comprised of the following command.
dir /a /b /-p /o:gen >filelisting.txt
Run this, then you can either add the individual profiles/paths where needed, or you can bring this list into MS Excel and using a copy/paste
macro generate your paths/profiles and export out the spreadsheet as a space delimited text file.
To be able to add this command to Windows Explorer
so you can generate file lists within any directory you're in, go to the following link to see how to add this as a custom file command within explorer.
http://www.theeldergeek.com/file_list_generator.htm
When you have to process literally hundreds of SWFs for flash courseware for example, this JSFL/Batch command combo is a MAJOR time saver. Thanks
Posted by: Kurt Melander at September 28, 2004 06:26 PMURL:
I can't seem to get the publish profile to work. IS it the name of a profile in the default publish profiles directory? And, if I am not using the swf output path option would two tabs after the fla name work? Can I have a publish profile without the swf output path??
Thanks for Sharing also!
Posted by: Brook at February 25, 2005 04:11 AMURL:
This is damn handy, so nice that i wrote a little ruby script to generate the bulk of the compile schema text file.
you can check it out here :
http://relivethefuture.com/choronzon/2005/08/automated-publishing.html
its just a shame that jsfl doesnt have a flfile.chooseDirectory command which would improve these kinds of tasks no end.
anyway, thanks for the command its a real time saver.
Posted by: martin wood at August 21, 2005 02:59 PMURL:
Sorry, but I can't make it run correctly, it says:
ReferenceError: FLfile is not defined
And it marks line 25 of the compileProject.jsfl
Do I have to install something else?
Posted by: Alejandro Biondo at May 25, 2006 02:15 AMURL:
Alejandro, you need to install the Flash 7.2 update, which is shipped with the FLfile extension, allowing jsfl to access the file system.
Posted by: Lanny at May 25, 2006 09:24 AMURL: http://gskinner.com
How do i publish an EXE with JSFL ?
Posted by: Mangesh at August 30, 2006 09:08 AMURL:
I have created some code that converts a Flash project file outputing the text for a schema so it can be bulk published with the above JSFL function, find out more here http://www.flashdynamix.com/blog/index.php/2007/04/11/how-to-bulk-publish-flas/
Posted by: Shane McCartney at April 12, 2007 05:57 AMURL: http://www.flashdynamix.com
Very handy script. The inly thing missing is that the flash.exe IDE stays open at the end. This prevents from calling the jsfl file from a command line script to batch compile flash as well as other sources.
Anyone knows how to close the flash executable at the end of the script? I looked at the flash documentation but did not find any methods for this.
Posted by: B at August 22, 2007 06:28 AMURL:
This is an answer to my own post : B at August 22, 2007 06:28 AM
Apparently I am somewhat blind!!
The following command closes flash
fl.quit( false );
Posted by: B at August 22, 2007 06:32 AMURL:
To get the publish profile to work change the line that calls the compile function to use row[2] instead of row[1] - that's a bug.
When the schema format comprises of
flafileswffiledefault
where default is the 'default' publish profile after parsing operation, the row[0] corresponds to flafile, row[1] corresponds to swf file & row[2] corresponds to publish profile
Below is a snippet of the fix
if (!FLfile.exists(dirURI+flaName)) { appendToLog(">> ERROR: FLA not found: "+flaName); error=true; continue; }
compile(dirURI+flaName,row[2],flaName);
------------
Also you can change the publish to use your own profile by placing a custom.xml & importing it in your jfsl script...below is a example snippet
.
.
. doc.importPublishProfile("file:///C:/Documents and Settings/user/Local Settings/Application Data/Macromedia/Flash 8/en/Configuration/Publish Profiles/custom.xml");
doc.currentPublishProfile = p_profile;
if (doc.currentPublishProfile != p_profile) { appendToLog(">> ERROR: Could not set publish profile ("+p_profile+"): "+p_fileName); error=true; }
.
.
.
Good luck
Posted by: Arvind at April 2, 2008 09:04 PMURL:
Great post! Led me into using JSFL for massive FLA compilation, the frustrating process we had performed manually. I owe you forever, thanks!
Posted by: Antalas at April 13, 2008 03:12 AMURL:
hi there i just saw tis post and this "tool" is going to be so usefull !!!
tx a lot
a little question i don't understand what a "profile" is?
Posted by: papa at July 29, 2008 09:23 AMURL:
I keep getting: "ERROR: Could not set publish profile"
Any help? Also, if there is no publish profile, will it compile with the settings that you last saved into the fla?
Great tool! Thank you!
Posted by: Tommy at December 12, 2008 11:59 AMURL:
I've looked all over the web and now I have to start asking. Does anyone here know of a way to get hand jsfl the file name of the .fla it's currently acting on? I want to use the .fla name as the prefix of some clips on my pages.
Thanks,
Steve
Posted by: Steve at January 20, 2009 09:24 AMURL:
Never late to say thanks :-)
Two more things:
In one post above, we can use fl.configURL for the part "file:///C:/Documents and Settings/user/Local Settings/Application Data/Macromedia/Flash 8/en/Configuration/".
And since there's no fl.currentDirectory, as well as fl.scriptURL returns no currentDirectory information, one might think that we have to use fl.browseForFileURL, which forbids the full automation. Well, instead of:
var schemaURI = fl.browseForFileURL("open","Please select your compile schema:",false);
You can:
var schemaURI = "file:///compile_schema.txt";
where the compileProject.jsfl and compile_schema.txt are in the same directory, where you run "flash.exe compileProject.jsfl".
Did not try the command outside the directory, though.
Posted by: blue at May 7, 2009 08:38 AMURL: