将对象存储在关联数组中

时间:2017-01-27 12:24:11

标签: javascript extendscript after-effects

如何将ExtendScript对象存储在关联数组中?

var assArray = {};

for (i=1; i<=app.project.items.length; i++) {
    //alert(app.project.item(i).name); one of them is "_vegs"
    assArray[app.project.item(i).name] = app.project.item(i);
}

alert(assArray["_vegs"].name);

此代码在第二个警报行返回错误。

Unable to execute script at line 9. undefined is not an object.

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

var assArray = {};

for (i=1; i<=app.project.items.length; i++) {
    //alert(app.project.item(i).name); one of them is "_vegs"
    assArray[app.project.item[i].name] = app.project.item[i];
}

alert(assArray["_vegs"].name);

我认为问题在于(i)希望[i]能够发挥作用