【问题标题】:Checking 'Use Count' for library items with JSFL使用 JSFL 检查库项目的“使用计数”
【发布时间】:2013-03-17 21:23:13
【问题描述】:

我已经做了一些研究,从我读到的内容来看,在 Flash IDE 中的“选择未使用的项目”似乎在 JSFL 中没有等效项。

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

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

【问题讨论】:

    标签: flash jsfl


    【解决方案1】:

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

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

    FUEL - Better Use Count

    存在的脚本会检查手动选择的库项目的使用计数。它的设计非常智能,它甚至会检查项目是否包含链接名称,但不一定在舞台上。这是为了确保您不会删除任何可能被动态实例化的项目。我所做的是将现有代码放入一个 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 似乎负责这项工作。原文的代码许可是 The MIT License (MIT)。

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

    Download: Remove Unused Library Symbols.jsfl

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      选择未使用的库项目 - 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');
      

      【讨论】:

        猜你喜欢
        • 2012-09-05
        • 2010-12-15
        • 2017-10-01
        • 2013-10-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-18
        • 1970-01-01
        • 2017-07-07
        相关资源
        最近更新 更多