Last active
May 14, 2021 09:36
-
-
Save ThirdPartyNinjas/7572994 to your computer and use it in GitHub Desktop.
Simple script to export Flash library items to png files. Doesn't check for invalid file names, and fails if the item is nested in multiple folders. Tested with Adobe Creative Cloud Flash Professional CC, (trial version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Usage: | |
//1) Save this file to disk. | |
//2) Load the target *.fla file in Flash. | |
//3) Commands | Run Command, Choose this file. | |
//4) Choose a target output folder, then sit back and wait. | |
fl.outputPanel.clear(); | |
var outputScaleFactor = 2; | |
var folderURI = fl.browseForFolderURL('Select output folder'); | |
var doc = fl.getDocumentDOM(); | |
var newDoc = fl.createDocument(); | |
var newDom = fl.getDocumentDOM(); | |
for(i in doc.library.items) | |
{ | |
var currentItem = doc.library.items[i]; | |
if(currentItem.itemType == "graphic" || | |
currentItem.itemType == "bitmap" || | |
currentItem.itemType == "movie clip") | |
{ | |
exportItemAsPng(currentItem, outputScaleFactor); | |
} | |
} | |
fl.closeDocument(newDoc, false); | |
function exportItemAsPng(item, scaleFactor) | |
{ | |
var itemName = item.name.split('.')[0]; | |
var exportPath = folderURI + "/" + itemName + ".png"; | |
newDoc.addItem({x:0.0, y:0.0}, item); | |
newDom.library.selectItem(item.name, false); | |
newDoc.scaleSelection(scaleFactor, scaleFactor); | |
// verify that the path exists | |
// this will still fail if the library item is more than one folder deep | |
FLfile.createFolder(exportPath.substring(0, exportPath.lastIndexOf("/"))); | |
if(item.itemType == "movie clip") | |
newDoc.exportInstanceToPNGSequence(exportPath); | |
else | |
newDoc.exportPNG(exportPath, true, false); | |
newDoc.deleteSelection(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello ThirdPartyNinjas,
Do you know by any chance how to do the same stuff,but for every frame of an animation,and for every layer ? Also,I'd like to manage the possibility of a layer inside folder,like a folder 'tree' (possible recursivity),and layer is 'snail',on 4th frame,have an output file tree.snail.004.png ?
Thanks for the script,
Simon