フレーム上のすべてのアイテムを選択し、#0000ffなどの特定の色に一致するすべてのストロークを削除できるjsfl関数を探しています
基本的に私は赤鉛筆のストロークを使って鉛筆ツールでたくさんのメモを書きます。しかし、Imが完了したら、フラッシュに、画面からすべての赤いストロークを削除し、他のすべてをそのままにしておくように指示したいと思います。これに対する解決策はありますか?
良い質問 !
JSFLドキュメントのDocumentオブジェクトを見ると、Strokeを取得する唯一の方法は、煩わしいdocument.getCustomStroke()を使用することです。理想的には、シェイプオブジェクトはストロークと塗りつぶしの情報を保存しますが、保存しません:(
配列を使用して選択を制御しようとしました:
var doc = fl.getDocumentDOM();
doc.selectAll();
var s = new Array().concat(doc.selection);
var sl = s.length;
doc.selectNone();
for(var i = 0; i < sl ; i++){
doc.selection = s[i];
stroke = doc.getCustomStroke('selection')
fl.trace(stroke.color)
}
それはうまくいきませんでした。
次に、を使用して各オブジェクトを選択しようとしました
doc.mouseClick({x:s[i].x, y:s[i].y}, false, false);
ただし、ノートはどのような形でもかまいません。そのため、ノートの左上隅をクリックすると、選択を逃す可能性があります。選択範囲を取得するためだけに各ピクセルをループすることはできません。
簡単な答えは、ストロークの色を取得する唯一の方法がドキュメントの選択によるためではありません。
ただし、いくつかの回避策があります。
IDEで、[検索と置換]を使用し、[テキスト]ではなく[色]を選択して、メモの色を透明なものに置き換えます。残念ながら、これはあまり解決策ではありません。メモを削除するのではなく、単に非表示にします。
(出典:sonic.net)
jsflからメモを簡単に取得できるようにします。現在のタイムラインのすべてのメモを1つのレイヤーに配置し、「_ notes」などのわかりやすい名前を付けてから、そのレイヤーを削除します。
例えば
var doc = fl.getDocumentDOM();
if(!doc) alert('Pardon me! There is no document open to work with.');
fl.trace(deleteLayerByName('_notes'))
/*Returns true if the layer was found and deleted, otherwise returns false*/
function deleteLayerByName(name){
var timeline = doc.getTimeline();
var frame = timeline.currentFrame;
var layers = timeline.layers;
var layersNum = layers.length;
for(var i = 0 ; i < layersNum; i++){
if(layers[i].name == name){
timeline.deleteLayer(i)
return true;
}
}
return false;
}
うまくいけば、誰かがjsflで色でオブジェクトを選択するための素晴らしいハックを提供できるでしょう。IDEでできることはたくさんありますが、JSFLからはできません:(
HTH
最近、いくつかの古いFLAファイルを処理する必要があり、同様のことをしなければなりませんでした。以下のコードは、現在のドキュメントのすべてのレイヤーとフレームで一致するすべてのストロークを検索します。
FlashCS6でテスト済み。
これはドキュメントを変更済みとしてマークしないことに注意してください。そのため、保存できるようにするには、何らかの方法でドキュメントを変更する必要があります。
var dom = fl.getDocumentDOM();
var timeline = dom.getTimeline();
/*
MODIFY THE KEYS IN THIS TABLE.
*/
var coloursToDelete = {
'FF0000': true,
'FFFF00': true,
};
var replacements;
var srcColour;
var layerName;
// Make sure all colours are lowercase and start with a #
for(var colour in coloursToDelete)
{
var val = coloursToDelete[colour];
delete coloursToDelete[colour];
if(colour[0] !== '#')
colour = '#' + colour;
coloursToDelete[colour.toLowerCase()] = val;
}
// Make sure to clear the selection, or the script will crash?
dom.selectNone();
fl.outputPanel.clear();
var deleteCount = 0;
// ----------------------------------------------------
// Loop through all layers
for(var layerIndex in timeline.layers)
{
var layer = timeline.layers[layerIndex];
if(!layer.visible)
continue;
// ----------------------------------------------------
// Loop through all frames of the current layer
for(var frameIndex = 0; frameIndex < timeline.frameCount; frameIndex++)
{
var frameDeleteCount = 0;
var frame = layer.frames[frameIndex];
if(!frame)
continue;
// ----------------------------------------------------
// Loop through all elements in the current frame
for(var elementIndex in frame.elements)
{
var element = frame.elements[elementIndex];
if(!element)
continue;
if(element.elementType !== 'shape')
continue;
// ----------------------------------------------------
// Check each edge in the current shape
for(var edgeIndex in element.edges)
{
var edge = element.edges[edgeIndex];
var stroke = edge.stroke;
var fill = stroke ? stroke.shapeFill : null;
if(!fill)
continue;
if(fill.color in coloursToDelete)
{
stroke.shapeFill = null;
edge.stroke = fill;
deleteCount++;
frameDeleteCount++;
}
}
}
// A quirk of deleting strokes like this is that shapes won't automatically merge like they would when deleting a stroke in the editor.
// Selecting then deselecting will force this to happen
if(frameDeleteCount > 0)
{
dom.selectAll();
dom.selectNone();
}
}
}
fl.trace('-- ' + dom.name + ': Deleted ' + (deleteCount) + ' strokes.');