【问题标题】:Loop not finishing循环未完成
【发布时间】:2013-01-21 02:28:40
【问题描述】:

由于某种原因,尽管importedChar.numItems =2,我的循环只经过一次

After Effects 项目从 1 开始而不是 0,所以我使用 x=1,这就是我所拥有的

for(x=1; x < importedChar.numItems; x++) {
    if (importedChar.item(x) instanceof CompItem) {
        //Add imported Char to Main Comp
        var newObj = null;      
        var newObj = myComp.layers.add(importedChar.item(x))

        //Move Layer under null
        newObj.moveAfter(newNull);

        //Parent to Null
        newObj.parent = newNull;
    }    
}

如果第一项是合成,则运行良好,但如果是第二项则退出循环

【问题讨论】:

  • x=1 只有 2,即 not
  • 如果 x=1x++,那么 x 只会小于 2 一次。你可能想要x &lt;= importedChar.numItems
  • 你必须使用x &lt; importedChar.numItems + 1
  • @Blender - x &lt;= importedChar.numItems 更可取
  • @kinsho:这是个人喜好。我发现查看+ 1 更容易。

标签: javascript loops if-statement after-effects


【解决方案1】:

您需要使用&lt;= 而不是&lt; 让它运行两次。

编辑:或者,for(x=0; x &lt; importedChar.numItems; x++) {,然后在需要时使用x+1,但在可以避免这种情况的情况下,最好使用&lt;=

当您需要访问索引一个有意义的值(例如,打印人性化的错误消息)时,通常会出现您想要替代的情况

【讨论】:

    【解决方案2】:

    x = 1, importedChar.numItems =2, x &lt; importedChar.numItems true;

    然后x = 2, importedChar.numItems =2, x &lt; importedChar.numItems false; 所以退出循环

    我猜是这样的

    【讨论】:

      猜你喜欢
      • 2021-03-18
      • 2020-11-27
      • 2020-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-29
      • 2019-06-18
      • 2015-02-28
      相关资源
      最近更新 更多