JSFL:删除与特定颜色匹配的所有笔画?

发布于 2024-09-07 16:14:22 字数 146 浏览 2 评论 0 原文

我正在寻找一个 jsfl 函数,它可以选择框架上的所有项目并删除与特定颜色匹配的所有笔划,例如 #0000ff

基本上我用铅笔工具使用红色铅笔笔划做了很多笔记。但当我完成后,我只想告诉闪光灯从屏幕上删除所有红色笔画,并保持其他所有内容完好无损。有什么解决办法吗?

I'm looking for a jsfl function that can select all items on a frame and delete all strokes that match a specific color such as #0000ff

Basically I make a lot of notes with the pencil tool using red pencil strokes. But when Im done I just want to tell flash to delete all my red stokes from the screen and leave everything else intact. Any solutions to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

能怎样 2024-09-14 16:14:22

好问题!

查看 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);

,但这并不是很有帮助,因为注释可以采取任何形状,
因此,可能会错过注释左上角的点击
选择。
仅仅为了获得选择而循环遍历每个像素是行不通的。

简短的回答不是因为检索描边颜色的唯一方法
是通过文档选择。

不过,有一些解决方法:

  1. 在 IDE 中,使用“查找和替换”,选择“颜色”而不是“文本”
    并将笔记颜色替换为透明的颜色。很遗憾
    这不是一个解决方案。它只会隐藏笔记,不会删除它们。
    flash 查找并替换></a><br />
<sub>(来源:<a href=sonic.net

  2. 方便从jsfl获取笔记:将所有笔记放在当前
    时间轴放在一层中并给它一个暗示性的名称,比如“_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

Good question !

Looking at the Document object in the JSFL documents I see the only way to retrieve a Stroke is through document.getCustomStroke() which is annoying. Ideally the Shape Object would store Stroke and Fill information, but it doesn't :(

I tried to control the selection using arrays:

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)
}

That didn't work.

Then I tried to select each object using

doc.mouseClick({x:s[i].x, y:s[i].y}, false, false);

but that's not very helpful as the notes can take any shape,
so a click at the note's top left corner might be a missed
selection.
Looping through each pixel just to get a selection wouldn't work.

Short answer is not because the only way to retrieve the stroke color
is through the document selection.

There are some workarounds though:

  1. In the IDE, use Find and Replace, choose Color instead of Text
    and replace your note color with something transparent. Unfortunately
    this isn't much of a solution. It will just hide the notes, not delete them.
    flash find and replace
    (source: sonic.net)

  2. Make it easy to get the notes from jsfl: Place all the notes in the current
    timeline in one layer and give it a suggestive name, say '_notes', then just
    delete that layer.

e.g.

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;
}

Hopefully someone can provide a nice hack for selecting objects by colour in jsfl. There are quite a few things you can do in the IDE, but can't do them from JSFL :(

HTH

心房敞 2024-09-14 16:14:22

我最近需要处理一些旧的 FLA 文件,并且必须执行类似的操作。
下面的代码将查找当前文档的所有图层和框架中的所有匹配笔划。
在 Flash CS6 中测试。

请注意,这不会将文档标记为已修改,因此您需要以某种方式修改文档才能保存。

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.');

I've recently needed to process some old FLA files and had to do something similar.
The code below will find all matching strokes in all layers and frames of the current document.
Tested in Flash CS6.

Note that this won't mark the document as modified, so you will need to modify the document in some way to be able to save.

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.');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文