Skip to content

Instantly share code, notes, and snippets.

@dopiaza
Created November 23, 2013 13:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dopiaza/7614901 to your computer and use it in GitHub Desktop.
Save dopiaza/7614901 to your computer and use it in GitHub Desktop.
Batch convert .fla to .png, rescaling as we go
// Based on Dan Catt's https://github.com/revdancatt/CAT422-glitch-location-viewer/blob/master/tools/convert-fla-to-png.jsfl
// Updated by David Wilkinson (@dopiaza):
// - scale fla before exporting as png
// - close file if exception thrown
// Open a folder of fla files, and then output them in a parallel
// folder called "output"
//
// This is very rough and ready and needs babysitting for the files
// that don't work.
//
// Good luck!
var scale = 2.0
var folder = fl.browseForFolderURL("Choose a folder to publish:");
var files = FLfile.listFolder(folder + "/*.fla", "files");
for (file in files) {
var curFile = files[file];
// Keep track of which document is open so we can close it if exception
var openDom = null;
// open document, export, and close
try {
fl.openDocument(folder + "/" + curFile);
var exportFileName = folder + '/../png/' + fl.getDocumentDOM().name.replace('.fla','.png');
var originalDom = fl.getDocumentDOM();
openDom = originalDom;
originalDom.selectAll();
originalDom.clipCopy();
var w = originalDom.width;
var h = originalDom.height;
fl.closeDocument(originalDom);
openDom = null;
fl.createDocument();
dom = fl.getDocumentDOM();
openDom = dom;
dom.width = w * scale;
dom.height = h * scale;
dom.clipPaste();
dom.selectAll();
dom.group();
dom.scaleSelection(scale, scale);
dom.align("vertical center", true);
dom.align("horizontal center", true);
dom.exportPNG(exportFileName, true, true);
dom.close(false);
openDom = null;
} catch(er) {
fl.trace(curFile);
fl.trace(er);
fl.trace('----------------');
if (openDom != null) {
openDom.close(false);
}
}
}
@tmorelli
Copy link

Thanks! It will die when it finds an fla with a locked layer. I added this check. After you do the select all, make sure you have something:
originalDom.selectAll();
var theSelectionArray = originalDom.selection;
if (theSelectionArray.length > 0){

...}

else{
fl.closeDocument(originalDom);
openDom= null;
}

I couldnt get it to automatically unlock the layers, but if you are doing tons of flas at once and dont care if you miss some, this little tweak will keep it from crashing

@spasannobudd
Copy link

how do i use this :P

@AwesomeWithRex
Copy link

how to use

@Shalalaguy
Copy link

how do i use this :P

idk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment