我有一個很奇怪的問題(怪異的,因爲它是特定於一個組件)與applicationComplete在一個相當簡單的應用程序中。所有UI組件都在MXML中聲明。我可以在applicationComplete中訪問它們,但不是spark.components.TextArea組件,名爲taStatus here;它在處理程序中爲null。textArea組件在applicationComplete事件上爲空
MXML看起來有點像這樣(有很多其他成分,但沒有什麼特別)
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="710" minHeight="640" applicationComplete="onApplicationComplete(event)" width="710" height="640">
<mx:TabNavigator left="15" right="15" top="15" bottom="340" paddingTop="0">
<s:NavigatorContent label="General" width="100%" height="100%">
<s:Label x="93" y="71" text="Label" id="lblTest"/>
</s:NavigatorContent>
<s:NavigatorContent label="Status" width="100%" height="100%">
<s:TextArea id="taStatus" width="100%" height="100%" text="Startup." editable="false"/>
</s:NavigatorContent>
</mx:TabNavigator>
<fx:Script source="main.as" />
</s:Application>
這裏是main.as
protected function onApplicationComplete(event: FlexEvent) : void
{
lblTest.text = 'abc789'; // OK
taStatus.text = 'abc789'; // Fail
}
類型錯誤處理程序:錯誤#1009:無法訪問空對象引用的屬性或方法。所以taStatus是null ...這個TextArea有什麼特別之處?
更新 2010-06-12 02:53 移動上述所有其他選項卡中的NavigatorContent(標籤)突然使文本域實例化的時間。非常奇怪,因爲所有的組件都在創建;我可以看到他們。
完美的解決方案/答案。感謝DanK;這開始讓我瘋狂;-) – Atorian 2010-06-11 23:57:13
完美的答案! – Penuel 2011-01-08 07:00:22