私のとっておきのJSFL。
タイムラインの空のレイヤーを一括削除するのが主な目的ですが、補助機能としてレイヤーカラーを整えます。
レイヤーカラーは適当な色になることが多いので、綺麗なflaづくりに役立ちます。
//delete empty layers
var l = 0;
var timeline = fl.getDocumentDOM().getTimeline();
execDelete();
function execDelete() {
var layersConut = timeline.layerCount;
if(l >= layersConut || layersConut == 1) return;
var currentLayer = timeline.layers[l];
//skip when layer is folder
if(currentLayer.layerType == "folder") next(true);
//check all start frame on layer
var frameArray = currentLayer.frames;
for (i=0; i<frameArray.length; i++) {
if (i == frameArray[i].startFrame) {
//check empty frame
if(chkFrame(frameArray[i])) next(true);
}
}
//delete a empty layer
fl.getDocumentDOM().getTimeline().deleteLayer(l);
next(false);
}
/* return true when layer is not empty*/
function chkFrame(frame)
{
var el = frame.elements;
var lb = frame.labelType;
var snd = frame.soundName ;
var as = frame.actionScript;
if( el != "" || lb != "none" || snd != "" || as != "") {
return true;
}else{
return false;
}
}
function next(b)
{
if(b) l++;
execDelete();
}
// coloring
var l = 0;var timeline = fl.getDocumentDOM().getTimeline();
var max = timeline.layerCount;
for(var i=0; i<max; i++)
{
var currentLayer = timeline.layers[i];
var color = 0xFF * (1 - i/max);
var resultColor = 0x0;
resultColor += color << 16;
resultColor += color << 8;
resultColor += color << 0;
currentLayer.color = resultColor;
switch(currentLayer.name.toLowerCase())
{
case "actions":
case "action":
case "as":
case "script":
currentLayer.color = 0x990000;
break;
case "label":
case "labels":
currentLayer.color = 0x3399FF;
break;
}
}