我曾尝试将对象添加到ArrayCollection内的ArrayCollection中,但它不起作用。我在下面的实现中得到错误#1009:
for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
identifyArrayCollection[x].speedsArrayCollection.addItem(speedsObj);
}我可以将speedsObj添加到不在ArrayCollection中的ArrayCollection中。
任何帮助都将不胜感激。
谢谢,
标记
发布于 2012-04-19 01:32:16
下面的代码将项speedObj添加到在名为identifyArrayCollection的ArrayCollection的索引x处找到的ArrayCollection中。
identifyArrayCollection.getItemAt(x).addItem(speedsObj);这就是你要找的吗?
您拥有的代码执行以下操作:
identifyArrayCollection[x]
//accesses the item stored in identifyArrayCollection
//with the key of the current value of x
//NOT the item stored at index x
.speedsArrayCollection
//accesses the speedsArrayCollection field of the object
//returned from identifyArrayCollection[x]
.addItem(speedsObj)
//this part is "right", add the item speedsObj to the
//ArrayCollection发布于 2012-04-19 03:32:53
假设identifyArrayCollection是包含某些对象的ArrayCollection,speedsArrayCollection是定义为identifyArrayCollection中包含的Object类型的变量的ArrayCollection
您应该执行以下操作:
for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
identifyArrayCollection.getItemAt(x).speedsArrayCollection.addItem(speedsObj);
}发布于 2012-04-19 07:57:27
不要忘记,任何复合对象都需要首先进行初始化。例如(假设初始运行):
有两种方法可以做到这一点:搭载@Sam
for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
if (!identifyArrayCollection[x]) identifyArrayCollection[x] = new ArrayCollection();
identifyArrayCollection[x].addItem(speedsObj);
}或者使用匿名对象,如果你真的想使用显式的命名约定-但是要知道,这些都是而不是编译时检查的(也不是使用数组访问器的任何东西):
for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
if (!identifyArrayCollection[x])
{
var o:Object = {};
o.speedsArrayCollection = new ArrayCollection();
identifyArrayCollection[x] = o;
}
identifyArrayCollection[x].speedsArrayCollection.addItem(speedsObj);
}https://stackoverflow.com/questions/10214490
复制相似问题