2011-08-26 40 views
0

我目前使用Adobe Flash Builder的最新版本来创建移动应用程序。对于应用程序来说,一个功能是允许用户为内容添加书签,这是通过将要书签的对象的ID存储到设备上的SQLite数据库中完成的。这部分已成功完成,并且它们存储良好。从ArrayCollection中检索对象物品信息?

现在我想做的是从数据库中拉回书签ID,并将它们传递给需要对外部数据库进行的WebService调用。当我从本地数据库中检索书签ID时,它们被包含在对象中,现在我需要找到一种方法,从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);     
       }    
      } 

现在,当我测试应用程序一切似乎罚款和跟踪语句返回如下:

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 

但是我又试图填充诠释值为每个对象到一个新的数组使用下面的代码:

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); 

我不明白为什么我收到此错误,任何人都可以请帮助?谢谢

+0

ehm,你没有实例化那个数组:'var ids:Array = []' – RIAstar

回答

0

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

var ids:Array = []; 

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

+0

OMG正在模拟那么多的数组,我忘了初始化它哈哈!对于这个愚蠢的问题感到抱歉,但那是星期五。感谢您的快速回复 :-) – user723858