Batch image exporting from .fla
http://journal.reallyenglish.com/2010/01/30/batch-image-exporting-from-fla.html
JSFL for Exporting Layers as Individual PNGs
http://summitprojectsflashblog.wordpress.com/2008/11/03/jsfl-for-exporting-layers-as-individual-pngs/
Export Flash library items as PNG’s with JSFL
http://abitofcode.com/2011/11/export-flash-library-items-as-pngs-with-jsfl/
最後組出以下程式,
將主時間軸上,每個 layer 的每個 frame 都會獨自輸出一張 png 圖檔,輸出檔名是由 layer.name 與 frame 組合而成。
var doc = fl.getDocumentDOM();
var lyrs = doc.getTimeline().layers;
var len = lyrs.length;
var lyr;
var originalType;
var i;
// Get a save location.
var saveDir = fl.browseForFolderURL("Choose a folder in which to save your exported PNGs:");
if (saveDir) {
// Get the Flash document's name, and strip off the final ".fla", and build a base name for the exported files.
fl.outputPanel.clear();
var docName = doc.name;
var extensionIndex = docName.lastIndexOf(".fla");
if (extensionIndex == docName.length - 4) {
docName = docName.substring(0, extensionIndex);
}
// Acceptable values are "normal", "guide", "guided", "mask", "masked", and "folder".
var originalTypes = new Array();
// Grab all original layer types. Need to do this before setting to guide, because otherwise a mask layer turned
// to guide would would turn a masked layer into a normal layer.
for (i=0; i < len; i++) {
lyr = lyrs[i];
originalTypes[i] = lyr.layerType;
};
// Guide all layers.
for (i=0; i < len; i++) {
lyr = lyrs[i];
lyr.layerType = "guide";
lyr.visible = false;
};
var tl = doc.getTimeline();
var frameCount = tl.frameCount;
// Save layers that were originally "normal" as PNGs, one-by-one.
for (i=0; i < len; i++) {
lyr = lyrs[i];
originalType = originalTypes[i]
if (originalType == "normal" || originalType == "guided") {
lyr.layerType = "normal";
lyr.visible = true;
for(var k=0; k<frameCount; k++){
tl.currentFrame = k;
exportPng(lyr.name + "_" + k);
}
lyr.layerType = "guide";
lyr.visible = false;
}
// In this case, we need to loop backwards until we find the mask layer, then re-mask this layer, before we export.
if (originalType == "masked") {
for (var j=i; j >= 0; j--) {
if (originalTypes[j] == "mask") {
var maskLyrSearch = lyrs[j];
maskLyrSearch.layerType = "mask";
lyr.layerType = "masked";
maskLyrSearch.visible = true;
lyr.visible = true;
for(var k=0; k<frameCount; k++){
tl.currentFrame = k;
exportPng(lyr.name + "_" + k);
}
maskLyrSearch.layerType = "guide";
lyr.layerType = "guide";
maskLyrSearch.visible = false;
lyr.visible = false;
break;
}
};
}
};
// Reset all layers to their original types.
for (i=0; i < len; i++) {
lyr = lyrs[i];
lyr.layerType = originalTypes[i];
lyr.visible = true;
};
}
function exportPng(fn) {
var pngName = saveDir + "/" + fn + ".png";
doc.exportPNG(pngName, true, true);
fl.trace("Exported: " + pngName);
}