我正在嘗試開發基於移動的Flex應用程序。Flex移動ArrayCollection錯誤
在我的申請中,我有兩個意見。
我試圖從一個視圖傳遞的ArrayCollection作爲數據另一種觀點,而是試圖在第二視圖訪問的ArrayCollection,我得到一個錯誤..
這裏的代碼firstView.mxml:
dirSteps的是,我試圖傳遞給下一個視圖中的ArrayCollection ...
代碼從DetailDirection.mxml:
[Bindable]
private var directionList:ArrayCollection;
private function init():void {
directionList = new ArrayCollection(ArrayUtil.toArray(data));
// here, data should be my arraycollection, but throws above error on
// trying to access property (i.e Step, Distance etc ..) of ArrayCollection ...
trace(data.Distance);
}
Error: Unknown Property: 'Distance'. at mx.collections::ListCollectionView/http://www.adobe.com/2006/actionscript/flash/proxy::getProperty()[E:\dev\4.y\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:870] at views::DetailDirection/init()[C:\Documents and Settings\ARSENAL\Adobe Flash Builder 4.6\CityExplorer_v2.0\src\views\DetailDirection.mxml:21] at views::DetailDirection/___DetailDirection_View1_creationComplete()[C:\Documents and Settings\ARSENAL\Adobe Flash Builder 4.6\CityExplorer_v2.0\src\views\DetailDirection.mxml:6] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152] at mx.core::UIComponent/set initialized()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:1818] at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842] at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
是什麼原因造成這個錯誤?需要做什麼 ?
我在這裏失蹤的任何東西?
感謝
什麼是'MyObjectType'這裏 ?你在談論哪種類型的對象? – tomjerry 2012-03-11 04:44:42
^謝謝。你的soln工作。但是,當我嘗試在第二個視圖中存儲'data'的值時,像這樣.. 'private var arr:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(data));'然後嘗試訪問as .. '((arr as ArrayCollection).getItemAt(0)as MyObjectType).distance' ..它仍然拋出與「距離屬性未知」相同的錯誤... – tomjerry 2012-03-11 04:53:20
@tomjerry「MyObjectType」將是對象類型dataProvider中的對象。當你像這樣初始化ArrayCollection時,它被設置一次;可能在數據屬性設置之前。當您嘗試訪問值以查看錯誤時,您必須逐步完成代碼。 ArrayCollection是否有效?您嘗試訪問的項目是否存在於ArrayCollection中?它是否正確投射?最後,它是否有距離屬性? – JeffryHouser 2012-03-11 13:03:13