Archive

Archive for November, 2010

Flash JSFL Utility

November 12, 2010 Leave a comment

Back to Flash world after long time. Everything is good.

I found this utility useful especially when working with multiple fla;s which needs to exported on every time when launching the game. Everything goes fine, until there is an compile time error while launching. If there’s one, then launching the game with errors seems of no use.

The Flash JSFL utility does by checking for errors., There is no direct way( Not sure if there;s one atleast as per my knowledge, if there’s some hacky way of getting around please post that in comments), so reading the output of the compile panel and saving it to a text file , reading that text file contents and checking if there is any error or warning against that output.

If there’s no error flash would output in certain way like

0 Error(s), 0 Warning(s)

Right here were the steps to get into that

var exportSWFs=new Array();

exportSWFs.push(gameManager);

exportSWFs.push(game);

exportSWFs.push(logo);

Push your sequence of swf’s into an array. The gameManager could be of an array with values formed from source path of the fla and destination where the swf needs to be published.

for (var i = 0; i < exportSWFs.length; i++)

{

var documentObj= fl.openDocument(exportSWFs[i][0]);

documentObj.exportSWF(exportSWFs[i][1],true);

// creating a file name based on document

var docErrorURI= logDirURI + documentObj.name + “.errors”

// saving the contents of the errors

fl.compilerErrors.save(docErrorURI);

// reading the contents of the error from file

var contents = FLfile.read(docErrorURI);

// If there is no errors and warnings , it prints out like 0 Error(s), 0 Warning(s)

// getting errorCount from the above output; Not sure if regular expression works here

var errorCount = (contents.split(“Error(s)”)[0]).split(”)[(contents.split(“Error(s)”)[0]).length-2];

FLfile.remove(docErrorURI);

if (errorCount != “0”) {

// Dont want to continue with rest of export — I dont want to compile the fla with errors

success = false; break;

} }

if (success) {

// Do launch game here

}else{

alert(“There were errors in ” + documentObj.name);

}

Advertisements
Categories: Error, JSFL