获取数组中对象的索引
我正在构建一个插件,并使用 actionscript 将对象的选择保存在插画文档中,然后在以后引用它。
var arrObj:Array=new Array();
arrObj.push(app.activeDocument.selection[0]);
如果我现在在文档中选择相同的对象并检查它是否在数组中,它将返回 -1 作为索引值。
var id:int=arrObj.indexOf(app.activeDocument.selection[0]);
trace (id); //-1
为什么选择不被视为与数组中的同一对象?
I'm building a plugin and I'm using actionscript to save the selection of an object in an illustrator document and then reference it later.
var arrObj:Array=new Array();
arrObj.push(app.activeDocument.selection[0]);
If I select now the same object in the document and check if its in the array it returns a -1 for the index value.
var id:int=arrObj.indexOf(app.activeDocument.selection[0]);
trace (id); //-1
Why is the selection not considered the same object as in that of the array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种解决方法,可以将选定的对象保存在数组中,当在插画文档中再次选择该对象时,它会指出该对象在数组中的索引。选定对象的数据类型是“PathItems”,并且有一个名为 name 的变量。您所要做的就是将此变量设置为您选择的值并将其保存在另一个数组中。
现在,所选对象及其相应的名称值存储在同一索引的数组中...您可以使用名称变量将所有“PathItems”相互比较,如果名称匹配,则可以使用 .数组中的indexOf(“name”)方法。
I figured out a work around for saving the selected objects in an array and when selecting the object again in the illustrator document it would point out the index of that object in the array. Selected objects datatypes are "PathItems" and have a variable called name. All you have to do is set this variable to a value of your choice as well as saving it in an another array.
Now the selected object and its corresponding name value are stored in arrays at the same index...you can compare all "PathItems" to each other by using the name variable and if the names match then you can get the index by using the .indexOf("name") method in arrays.