从ArrayCollection中检索对象项目信息???

时间:2011-08-26 13:45:09

标签: android flex flash-builder arraycollection

我目前正在使用Adobe Flash Builder的最新版本来创建移动应用程序。对于应用程序,一个特征是允许用户通过将要加书签的对象的id存储到设备上的SQLite数据库中来对内容进行书签。这部分已经成功完成,存储得很好。

现在我想要做的是从数据库中取回已添加书签的id并将它们传递给需要对外部数据库进行的WebService调用。当我从本地数据库中检索Bookmark id时,它们包含在object中,我现在需要找到一种方法从ArrayCollection中的数据库对象获取id,并将它们存储在一个新的数组中,该数组将被传递给WebService,如Web服务期望一个Int的数组而不是对象。下面是我创建的代码,用于查看对象项是否在对象的数组列表中:

private function loop():void
            {
                var index:int;
                for( index = 0; index < compsCollection.length; index++ )
                {
                    trace( "Element " + index + " is " + compsCollection[index].comp_id );                  
                }               
            }  

现在,当我测试应用程序时,一切似乎都很好,trace语句返回以下内容:

Element 0 is 91
Element 1 is 9
Element 2 is 9
Element 3 is 9
Element 4 is 9
Element 5 is 9
Element 6 is 9
Element 7 is 282
Element 8 is 282
Element 9 is 282
Element 10 is 282
Element 11 is 282
Element 12 is 282

然而,我尝试使用以下代码将每个对象的Int值填充到一个新数组中:

var ids:Array;
                var index:int;
                for( index = 0; index < compsCollection.length; index++ )
                {
                    trace( "Element " + index + " is " + compsCollection[index].comp_id );
                    ids.push(compsCollection[index].comp_id);
                }               
            }

然而,当我运行此代码时,我收到此错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

此错误在线上发生:

ids.push(compsCollection[index].comp_id);

我不明白为什么我会收到此错误,有人可以帮忙吗?感谢

1 个答案:

答案 0 :(得分:0)

虽然我对Adobe Flash Builder一无所知,但通常在使用之前必须先实例化一个数组。

var ids:Array = []; 

也许?? (正如RIAstar建议的那样)