Skip to content

Instantly share code, notes, and snippets.

@debreuil
Created April 15, 2017 16:10
Show Gist options
  • Save debreuil/83d9e7ef667f58e06c5b8915f32223da to your computer and use it in GitHub Desktop.
Save debreuil/83d9e7ef667f58e06c5b8915f32223da to your computer and use it in GitHub Desktop.
fl.outputPanel.clear();
var trace = fl.trace;
fl.showIdleMessage(false);
var runOnAllItems = true;
var runOnAllFiles = true;
var runOnSubdirectories = false;
var flashDocs = [];
var docOrg = fl.getDocumentDOM();
var docOrgTl = docOrg.timelines[0];
var orgPath = docOrg.path;
folderName = orgPath.replace(/\\/g, "/");
folderName = folderName.substring(0, orgPath.lastIndexOf("/"));
folderName = folderName.replace(/:/, "|");
folderName = "file:///" + folderName;
//var profileXML = fl.getDocumentDOM().exportPublishProfileString('pngExport');
var cfDir = fl.configDirectory;
cfDir = cfDir.replace(/\\/g, "/");
cfDir = cfDir.substring(0, cfDir.lastIndexOf("/"));
cfDir = cfDir.replace(/:/, "|");
cfDir = "file:///" + cfDir;
trace(cfDir);
var exports;
function main()
{
if(runOnAllFiles)
{
findAllFlaFiles(folderName);
processAllFlaFiles();
}
else
{
processFla(fl.getDocumentDom());
}
}
function findAllFlaFiles(dir)
{
var files = FLfile.listFolder(dir + "/*.fla", "files");
trace("files: " + dir);
for(var f = 0; f < files.length; f++)
{
if(files[f][0] != "_") {
flashDocs.push(dir + "/" + files[f]);
}
}
if(runOnSubdirectories) {
var dirs = FLfile.listFolder(dir, "directories");
if(dirs != null)
{
for(var i = 0; i < dirs.length; i++)
{
findAllFlaFiles(dir + "/" + dirs[i]);
}
}
}
}
function processAllFlaFiles()
{
for(var i = 0; i < flashDocs.length; i++)
{
processFla(flashDocs[i], i);
}
}
function showAllLayers(timeline)
{
for (var i = 0; i < timeline.layersCount; i++) {
var layer = timeline.layers[i];
layer.locked = false;
layer.visible = true;
}
}
function processFla(path, index)
{
var doc = fl.openDocument(path);
trace("parse: " + path);
//doc.exportPNG(path, true, false);
//doc.close();
//return;
// docOrgTl.insertBlankKeyframe(index);
var tl = doc.timelines[0];
showAllLayers(tl);
trace(tl + ":" + tl.layerCount);
for(var i = 0; i < tl.layerCount; i++) {
var layer = tl.layers[i];
layer.locked = false;
layer.visible = true;
}
modifyDoc(doc);
//doc.publish();
tl.setSelectedFrames(0,1, true);
for(var i = 0; i < tl.layerCount; i++) {
tl.setSelectedLayers(i, true);
tl.copyFrames(0);
//tl.copyFrames(0);
docOrgTl.setSelectedLayers(i, true);
//docOrgTl.insertKeyframe(index);
//docOrgTl.setSelectedFrames(index,index+1,true);
docOrgTl.pasteFrames(index);
//docOrgTl.pasteLayers(0);
}
doc.save();
doc.close(false);
return;
// for (var i = 0; i < tl.frameCount; i++) {
// tl.currentFrame = i;
//var name = flName + "_" + flIndex + "_" + i + "_";
//var newProfileXML = profileXML.replace("<jpegFileName>test.jpg</jpegFileName>",
// "<jpegFileName>" + name + ".jpg</jpegFileName>");
//fl.getDocumentDOM().importPublishProfileString(newProfileXML);
if(runOnAllItems)
{
lib.selectAll();
lib.expandFolder(true, true);
lib.selectAll();
}
exports = null;
exports = {};
modifyDoc(doc);
if(runOnAllItems)
{
lib.selectAll();
lib.expandFolder(false, true);
lib.selectNone();
}
fl.saveDocument(doc);
doc.publish();
//}
}
function modifyDoc(doc)
{
//var pp = cfDir + "Publish Profiles/jpgExport.xml";
var pp = fl.configURI + "Publish%20Profiles/pngExport.xml";
trace(pp);
//doc.importPublishProfile(pp);
doc.importPublishProfile('file:////Users/rdebreuil/crowbar_working/_tests/pngExport.xml');
doc.currentPublishProfile = "pngExport";
return;
}
function processTimelines(obj)
{
var ar = [];
for(var i = 0; i < obj.length; i++)
{
curTimeline = obj.name; // only root level timelines have names (scenes)
var l = processTimeline(obj[i]);
ar.push(l);
}
return ar;
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment