5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Flash Pro] タイムラインのレイヤーをいい感じにする君.jsfl

Posted at

私のとっておきの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;
	}
}

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?