1

我做了一些研究,从我读过的内容来看,JSFL 中似乎没有与 Flash IDE 中的“选择未使用的项目”相同的东西。

有谁知道至少能够通过循环浏览整个图书馆来检查该项目是否被使用的属性?像 item.useCount...

我正在检查 adobe 文档,但找不到任何东西...

4

2 回答 2

2

编辑:所以我刚刚遇到了这个简洁的小菜单项,它可以选择未使用的项目……不需要 JSFL。它隐藏在库面板标题的上下文下拉菜单中。单击该下拉菜单,然后单击“选择未使用的项目”。Flash 将选择所有未使用的库项目,它甚至会跳过具有链接名称的库项目以进行动态实例化。所以这真的取决于你......你可以使用这个方法或下面的脚本。

我不能完全相信您在下面看到的代码,因为我正在使用一些我从位于此处的现有脚本中遇到的代码:

燃料 - 更好的使用计数

存在的脚本会检查以查看手动选择的库项目的使用计数。它的设计非常智能,它甚至会检查项目是否包含链接名称,但不一定在舞台上。这是为了确保您不会删除任何可能被动态实例化的项目。我所做的是将现有代码放在一个 for 循环中,该循环根据循环的当前项运行检查。

// Remove Unused Library Symbols


var dom = fl.getDocumentDOM();
if (dom == null)
{
    alert('Please open a file.');
}
else
{
    var lib = dom.library;
    var activeItem;
    var isFound;
    var item;
    var libItems = lib.items;

    fl.outputPanel.clear();

    for ( var i = 0; i < libItems.length; i++ )
    {
        var curLibItemName = libItems[i].name;
        var curLibItemSelection = lib.selectItem(curLibItemName, true, true);
        var selectedItem = lib.getSelectedItems();

        function scanTimeline(_timeline, _mainTimeline)
        {
            var timeline = _timeline;
            var layerCount = timeline.layerCount;

            while (layerCount--)
            {
                var frameCount = timeline.layers[layerCount].frameCount;

                while (frameCount--)
                {
                    if (timeline.layers[layerCount].frames[frameCount] == undefined)
                    {
                        continue;
                    }

                    var elems = timeline.layers[layerCount].frames[frameCount].elements;
                    var p = elems.length;

                    while (p--)
                    {
                        // Check if it's an instance in the library
                        if (elems[p].elementType == 'instance')
                        {
                            // Check if it's the same clip as our active check
                            if (elems[p].libraryItem.name == activeItem.name)
                            {
                                found = true;
                                var where;

                                if(_mainTimeline == true)
                                {
                                    where = 'Located in the main timeline.';
                                }
                                else
                                {
                                    where = 'Located in the library item: ' + item.name;
                                }

                                frameCount = 0;
                            }
                        }
                    }
                }
            }
        }

        function scanLibrary()
        {
            var items = lib.items;

            for (var i = 0; i < items.length; i++)
            {
                item = items[i];

                if(item.itemType == 'movie clip')
                {
                    scanTimeline(item.timeline, false);
                }
            }
        }

        // Safety check
        if (selectedItem.length == 0)
        {
            alert('Please make a selection in the library.');
        }
        else
        {
            activeItem = selectedItem[0];
            found = false;

            // Scan the main timeline first
            scanTimeline(dom.getTimeline(), true);

            // Scan the library
            scanLibrary();

            if (found == false)
            {
                if (activeItem.linkageClassName != undefined)
                {
                    fl.trace(curLibItemName + ' was not found on the stage, but it does have a linkage name so it may be instantiated dynamically.  Use caution before deleting.');
                }
                else
                {
                    fl.trace(curLibItemName + ' was not found on the stage and will be removed.');
                    lib.deleteItem(curLibItemName);
                }
            }
        }   
    }
}

正如我所提到的,我不能为此获得所有功劳,因为脚本的原始开发人员为此命令完成了大部分繁重的工作。在包含原始代码的 FUEL 页面中,Julian Dolce 似乎负责这项工作。原始的代码许可证是麻省理工学院许可证(MIT)。

您可以将上面的代码复制到一个新的 JSFL 文档中并将其保存在您的 commands 文件夹中,或者从下面的链接下载 jsfl 文件并将其放置在您的 commands 文件夹中。

下载:删除未使用的库 Symbols.jsfl

我希望这会有所帮助。

于 2013-04-01T01:18:45.420 回答
0

选择未使用的库项目 - Flash Pro CC

var unusedArr = fl.getDocumentDOM().library.unusedItems;

for(var i=0;i<unusedArr.length;i++) 
    fl.getDocumentDOM().library.selectItem(unusedArr[i].name,false,true);

fl.trace(unusedArr.length+' Items selected');
于 2014-03-21T20:55:09.403 回答