Hi.
You just need to copy the code below, open up a text editor, paste the code and save it to a file ending in .jsfl.
Then you can:
- Double click on the file;
- Or drag and drop it over Animate's IDE;
- Or place it in the Commands folder to run it.
To run the code from the commands folder, place it in one of the following paths:
macOS:
/Users/<USER>/Library/Application Support/Adobe/<ANIMATE_VERSION>/<LANGUAGE>/Configuration/Commands
E.g.:
/Users/johndoe/Library/Application Support/Adobe/Animate 2023/en_US/Configuration/Commands
Windows:
<BOOT_DEVICE>\Users\<USER>\AppData\Local\Adobe\Animate <ANIMATE_VERSION>\<LANGUAGE>\Configuration\Commands
E.g.:
C:\Users\johndoe\AppData\Local\Adobe\Animate 2021\en_US\Configuration\Commands
Then you can run the command in Animate by going to Commands > Your Command Name.
Export Keyframes as PNGs.jsfl. (the code has been updated in 12/02/2022)
var dom = fl.getDocumentDOM();
var timeline = dom.getTimeline();
var layers = timeline.layers;
var baseLayer = 0; // change this number if the first layer is a folder or other type that possibly doesn't have frames
var frames = layers[baseLayer].frames;
var filePrefix = dom.name.replace(".fla", "") + "_"; // the prefix doesn't need to contain the FLA name
var digits = 2; // 01, 001, 0002...
var folder;
function main()
{
if (!dom)
{
alert("Please open up a FLA first.");
return;
}
folder = fl.browseForFolderURL("Choose an output directory.");
if (!folder)
{
alert("No folder selected.");
return;
}
var i;
for (i = 0; i < frames.length; i++)
{
timeline.currentFrame = i;
lookForKeyframes(i);
}
}
function lookForKeyframes(frameIndex)
{
var i, layer;
for (i = 0; i < layers.length; i++)
{
layer = layers[i];
if (layer.layerType === "folder")
continue;
var frame = layer.frames[frameIndex];
if (!frame)
continue;
if (frame.startFrame == frameIndex && !frame.isEmpty)
{
dom.exportPNG(folder + "/" + filePrefix + zeropad((frameIndex + 1), digits) + ".png", true, true);
break;
}
}
}
function zeropad(number, length)
{
var str = '' + number;
while (str.length < length)
str = '0' + str;
return str;
}
main();
JSFL file download:
https://bit.ly/3ER3YEC
There's one edge case that I found in which the code won't detect a change in the visual of the timeline. I'll update the code if I can think of a solution.
Please let us know if you have any further questions.
Regards,
JC