Batch publish .fla files

JSFL is the way to automate tasks in Flash CS IDE, you can write extensions to do the repeating works like export fonts, open files, create symbols, read graphics datas, build multiple .fla files … The one thing i got astonished about is that there are no built-in way (no jsfl api) to know if there are errors during compilation of an .fla file. Hit ctrl+enter, you see that even if there are errors in code, the Flash IDE still trying to launch the .swf file. Hit build from an .flp project, the compiling process won’t stop when errors occurs for files, it just clear the log everytime a new file need to build, so we end up with a bunch of errors in files which we never where they are to apply the fixes.

I don’t know how hard it is for the Flash CS team to add an api allowing us to catch and stop when there are errors building .fla file, but this surely make enough troublesome for me : Once there are errors, i need to wait for the batch building complete then compile one by one manually… so finally decision, there must be a way to do it in jsfl.

The basic idea is although we can’t know directly if there are errors in the building process, we can save the compile errors into a temporary file, then read it back, parse the string and find if there are errors before trying to build the next one. Here is the simplest form :

function exportAll(){ 
	var docs=fl.documents;
	var docs_length=docs.length;
	for (var i=0; i<docs_length; i++) {  
		var doc=docs[i];
		var docErrorURI= "file:///c|/" + ".errors";;
		var contents	=;
		var arr	= contents.split("\n");
		var errorCount	= arr[arr.length-1].split(" ")[0];
		if (errorCount == 0){
		} else {

There are many other features you may want to add like open all .fla files inside a folder (with exceptions ?), delete .aso files, save file open state, monitor building log and allow continue build after errors for specific module is fixed or a specific .swf file to run after the build completes …

I might update the file with new features in future releases, but as it’s for now doing the job, i will stick with it at least for sometime. (there won’t be any planned updates in near future)

UPDATE 05.NOV.2011 ——————————————————————————————

For files that are not yet open, we have a way to build them directly, this resulted in faster compiled time. Using the method above to break the building stack if there are errors, we can now build a list of fla files within a single click. Remember that this is only available for flash CS4 10.0.2 and later. For earlier version of the IDE, you will still need to open the file before publish it.

And here is the code, you can change the basePath and the fileList once for each project and then you are good to go.

basePath	= "file:///D:/"
fileList	=	[	'file1.fla',

//CS5 :
for (i=0; i<fileList.length; i++){
	fl.publishDocument(basePath + fileList[i]);
	var docErrorURI= basePath + fileList[i].split(".fla")[0] + ".errors";;
	var contents	=;
	var arr	= contents.split("\n");
	var errorCount	= arr[arr.length-1].split(" ")[0];
	if (errorCount > 0) break;

Once again, this is not the ultimate solution, there are other features to add like checking for the IDE version by parsing fl.version so it will compatible with all IDEs. But at least it’s doing right for my need, i will keep this simple version.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s