Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 能否将对象添加到arraycollection内部的arraycollection?_Apache Flex_Arraycollection - Fatal编程技术网

Apache flex 能否将对象添加到arraycollection内部的arraycollection?

Apache flex 能否将对象添加到arraycollection内部的arraycollection?,apache-flex,arraycollection,Apache Flex,Arraycollection,我已尝试将对象添加到ArrayCollection中的ArrayCollection,但它不起作用。我在以下实现中遇到错误#1009: for (var x:Number = 0; x < identifyArrayCollection.length; x++) { identifyArrayCollection[x].speedsArrayCollection.addItem(speedsObj); } for(变量x:Number=0;x

我已尝试将对象添加到ArrayCollection中的ArrayCollection,但它不起作用。我在以下实现中遇到错误#1009:

for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
    identifyArrayCollection[x].speedsArrayCollection.addItem(speedsObj);
}
for(变量x:Number=0;x
我可以将speedsObj添加到不在ArrayCollection中的ArrayCollection

任何帮助都将不胜感激

谢谢


标记以下代码将项目
speedObj
添加到名为
IdentificationArrayCollection
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
假设 IdentificationArrayCollection是一个包含一些对象和 speedsArrayCollection是一个ArrayCollection,定义为IdentificationArrayCollection中包含的对象类型的变量

你应该做:

for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
    identifyArrayCollection.getItemAt(x).speedsArrayCollection.addItem(speedsObj);
}
for(变量x:Number=0;x
不要忘记,任何复合对象都需要先进行初始化。 例如(假设初始运行):

有两种方法可以做到这一点:借助@Sam

for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
   if (!identifyArrayCollection[x]) identifyArrayCollection[x] = new ArrayCollection();
   identifyArrayCollection[x].addItem(speedsObj);
}
for(变量x:Number=0;x
如果您确实想使用显式命名约定,也可以使用匿名对象—但是请注意,这些约定未在编译时进行检查(也未使用数组访问器):

for(变量x:Number=0;x
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);
}