Posted at

flaファイル内のフレームスクリプトを全部外部.asにするJSFL

More than 5 years have passed since last update.

出力パネルを使ってファイルの書き出しをする。


FrameScript2AS.jsfl

fl.outputPanel.clear(); 

var dom = fl.getDocumentDOM();
var dir = dom.pathURI.split(dom.name).join("");
var exportDir = 'as/';
var count = 0;

parseLibrary();

fl.outputPanel.clear();
fl.outputPanel.trace('total ' + count + ' files');

function parseLibrary()
{
var items = dom.library.items;
var len = items.length;
for (var i=0;i<len;i++)
{
var item = items[i];
var name = item.name;
var fileName = exportDir + name.split("/").join("-");

if (item.symbolType == "movie clip")
parseTimeline(fileName, item.timeline);
}
}

function parseTimeline(name, timeline)
{
var layers = timeline.layers;
var len = layers.length;
for (var i=0;i<len;i++)
parseLayer(name, i, layers[i]);
}

function parseLayer(name, index, layer)
{
name += ".L" + index;
var frames = layer.frames;
var len = frames.length;
for (var i=0;i<len;i++)
parseFrame(name, i, frames[i]);
}

function parseFrame(name, index, frame)
{
var fileName = name + ".f" + (index + 1) + ".as";
var script = frame.actionScript;
var replaceScript = 'include "' + fileName + '";';
if (frame.startFrame == index && !!script)
{
if (script == replaceScript) return; // include に差し替え済みのときは何もしない。

fl.outputPanel.clear();
fl.outputPanel.trace(script);
fl.outputPanel.save(dir + fileName, false, false);
frame.actionScript = replaceScript;
count++;
}
}