找到对象的次数

时间:2016-10-19 12:26:17

标签: javascript

此代码每次找到对象时都会提醒对象名称。如何使警告发现对象的次数

app.beginUndoGroup("Find  Keys"); // Start 
    var targetComp = app.project.activeItem; // Collect the active composition
    var selectedLayer = targetComp.selectedLayers; // Collect the selected layers

    for (e = 0; e <= selectedLayer.length-1; e++) { // Cycle through selected layers

        for (a = 1; a <= selectedLayer[e].transform.numProperties; a++) {; // Cycle through transform parameters
            var propToDelete = selectedLayer[e].transform.property(a); // Identify the parameter to find
            for (i = propToDelete.numKeys; i != 0; i--) { // Cycle through the Keyframes backwards
                alert(i); // Alert the current Keyframe
            }
        }
    }
    app.endUndoGroup(); // End 

2 个答案:

答案 0 :(得分:1)

您想要在第一个for循环之外定义变量并为其指定0 然后增加变量而不是警告i
然后在for循环之后,警告声明的变量

的值 像这样: var counter = 0之前的for (e =0; e...

counter++代替alert(i)

最后

alert(counter)

答案 1 :(得分:1)

只需在循环开始时添加变量count = 0,并在每次创建对象时添加1。最后只有alert变量count

    app.beginUndoGroup("Find  Keys"); // Start 
    var targetComp = app.project.activeItem; // Collect the active composition
    var selectedLayer = targetComp.selectedLayers; // Collect the selected layers
    var count = 0;
    for (e = 0; e <= selectedLayer.length-1; e++) { // Cycle through selected layers

        for (a = 1; a <= selectedLayer[e].transform.numProperties; a++) {; // Cycle through transform parameters
            var propToDelete = selectedLayer[e].transform.property(a); // Identify the parameter to find
            for (i = propToDelete.numKeys; i != 0; i--) { // Cycle through the Keyframes backwards
                alert(i); // Alert the current Keyframe
                count = count + 1; 
            }
        }
    }
    app.endUndoGroup(); // End
    alert(count);