F9 for actions

Some possibly useful and definitely unuseful ActionScript 3.0 code.

Nov 29

JSFL Script Failing or Timing Out

So in my latest endeavor of JSFL, I was building a panel that allows one to browse for an XML file that another program I built puts together. The xml file defines a set of FLA files and the number of scenes within that file. The file is loaded in and parsed out by actionscript, and once it’s all ready to be built I looped over the data and fired off a JSFL script to build each FLA file based on the specified parameters.

Now figuring out how to build the FLA file and add scenes was pretty easy, even the JSFL documentation made it pretty apparent how to do this:

function createFLATemplate( dir, filename ) {
	
	fl.createDocument("timeline");
	var newDoc = fl.getDocumentDOM();
	newDoc.height = 430;
	newDoc.width = 550;
	newDoc.framerate = 24;
	
	fl.trace( dir+"/"+filename+".fla" );
	fl.saveDocument( newDoc, dir+"/"+filename+".fla" );
	
}


The problems came about when I assumed that it would be no problem to call this JSFL process from AS3 in a loop. For some reason at very seemingly random points, the loop script would just die within the loop, sometimes it might get through half of the FLA files, or just a few, or nearly all of them. But very consistently it was never able to create all of the FLA files in one shot. My first inkling was that instead of doing this within a loop, I should turn it into a batch process and have the AS3 script wait for each file to be created before creating the next, it seemed like a full-proof idea. I was wrong. The batch process worked perfectly in theory, but again the JSFL script would just kill everything at some point in it’s processing.

The solution that I came up with was to keep the batch process in place, however I used setTimeout with a 500ms timeout. Not the most elegant solution, but this has fixed the problem, the JSFL script no longer dies, so I guess whatever processes that were running and getting tangled up now have sufficient time to clean themselves up for the next process to run.

public function fileComplete():void {
	curFile++;
	setTimeout( buildModule, 500 );
}


If anyone has any insight as to what the real problem is, I would really like to know, but it seems for now that if you are doing a pretty lengthy batch process of things with JSFL you just need to give it a little time to breathe.