gSkinner - Home

JSFL FLA Batch Compiler

Posted on August 19, 2004 by Grant Skinner

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.

Follow @gskinner on Twitter for more news and views on interactive media.
27 Comments

As for limitation #1, you can use fl.outputPanel.save();

As for #2, you can say:

fl.openDocument(fileURI);

fl.getDocumentDOM().testMovie(); // or publish()

Posted by: Keith Peters on Aug 19, 2004 10:51am 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 on Aug 19, 2004 11:02am URL: 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 on Aug 20, 2004 11:16am

Nice. Added this in and uploaded a new version - thanks Martin.

Posted by: Grant Skinner on Aug 20, 2004 3:03pm URL: http://gskinner.com/

nice work ! thanx !

Posted by: Francis Bourre on Aug 22, 2004 2:36pm URL: http://www.tweenpix.net

thanks a lot,

share your work is cool !

Posted by: Clément Hussenot on Aug 25, 2004 3:16pm

Grant,

thanks for this, I'll post about this on my site.

Posted by: eyezberg on Aug 29, 2004 2:41am 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 on Sep 28, 2004 6:26pm

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 on Feb 25, 2005 4:11am

JSFL FLA Batch Compiler

gskinner en este post, nos recomienda un la mejor forma de automatizar la tarea de compilar. Todos hemos tenido, alguna vez, la necesidad de compilar un gran numero de peliculas, de una forma rápida. Para este tipo de cosas, y...

Posted by: >> Slaveofthemind &… on Mar 4, 2005 2:06am URL: http://www.slaveofthemind.com/flashblog/archi…

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 on Aug 21, 2005 2:59pm

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 on May 25, 2006 2:15am

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 on May 25, 2006 9:24am URL: http://gskinner.com

How do i publish an EXE with JSFL ?

Posted by: Mangesh on Aug 30, 2006 9:08am

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 on Apr 12, 2007 5:57am URL: 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 on Aug 22, 2007 6:28am

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 on Aug 22, 2007 6:32am

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 on Apr 2, 2008 9:04pm

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 on Apr 13, 2008 3:12am

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 on Jul 29, 2008 9:23am

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 on Dec 12, 2008 11:59am

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 on Jan 20, 2009 9:24am

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 on May 7, 2009 8:38am

And an even later comment...

>> limitation #1, you can use fl.outputPanel.save();

Wouldn't fl.compilerErrors.save be a better option?

Posted by: Mike on Apr 25, 2010 8:21am

Tnx for you work!

Posted by: Nicolas on May 14, 2010 2:28am URL: http://tvxgames.ru

Grant this is an amazing little tool here, thank you. I actually tweaked it as well and don't know if there is interest in this. For us here, we go from Mac and PC plus different places to store the main code library. What I did was make the first line a code path reference like C:\TheProject\src

in the loop I tweaked it the following:

for (var i=0;i<l;i++) {
var row = schema[i].split(String.fromCharCode(9));
if(i == 0)
{
classPath = row[0];
appendToLog("\n---------------------------------------------------------------------------\nClass Path "+classPath+"\n---------------------------------------------------------------------------");
}
else
{
var flaName = row[0];

...

compile(dirURI+flaName,row[2],flaName,classPath);

...

function compile(p_fileURI,p_profile,p_fileName,p_classPath) {
fl.outputPanel.clear();
var doc = fl.openDocument(p_fileURI);

if(p_classPath != null && p_classPath != "")
{
var isLastCharacterAForwardSlash = p_classPath.lastIndexOf("/") == p_classPath.length - 1;

if(isLastCharacterAForwardSlash) p_classPath = p_classPath.substring(0, p_classPath.length);

if(doc.sourcePath.indexOf(p_fileURI) == -1) doc.sourcePath = p_classPath + doc.sourcePath;
}

and finally ...

var ok;

//if the new folder doesn't exists create a new one
var folderForNew = p_newName.substring(0, p_newName.lastIndexOf("/"));
if(!FLfile.exists(folderForNew)) FLfile.createFolder(folderForNew);

ok = FLfile.copy(p_file,p_newName);

(I hope I got it them all...)

Posted by: Kelly Vernon on Jan 24, 2011 12:19pm URL: http://www.cubedelement.com

Thanks very much for this script. After a few modifications I was able to use it in my build script. Replacing the file browser dialog prompt with "file:///---SCHEMAURI---/compile_schema.txt" I was able to use batch scripts and sed to create a new jsfl from this template and execute it:

set TOOLDIR=%CD%\tools
set JSFLOUTDIR=%CD:\=\/%
%TOOLDIR%\sed "s/---SCHEMAURI---/%JSFLOUTDIR%/" compileProject.jst > out\compileProject.jsfl
out\compileProject.jsfl
REM Cause some delay between compile and check for output file.
ping -a 1.1.1.1 > nul 2>nul
ping -a 1.1.1.2 > nul 2>nul
type compile_log.txt
IF NOT EXIST out\favoritesmenu.swf (
echo.File does not exist. Compile the project first.
pause
exit
)

Posted by: Jack on Dec 18, 2011 9:42am URL: http://none

Leave a Reply

Your email is never published nor shared.




You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>