我目前使用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);
我不明白爲什麼我收到此錯誤,任何人都可以請幫助?謝謝
ehm,你沒有實例化那個數組:'var ids:Array = []' – RIAstar