我在一个相当简单的应用程序中使用 applicationComplete 有一个奇怪的问题(很奇怪,因为它特定于一个组件)。所有 UI 组件都在 MXML 中声明。我可以在 applicationComplete 中访问它们,但不是spark.components.TextArea组件,这里命名为taStatus;它在处理程序中为空。
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
}
TypeError:错误 #1009:无法访问空对象引用的属性或方法。所以 taStatus 为空……这个 TextArea 有什么特别之处?
更新2010-06-12 02:53 将 NavigatorContent(选项卡)移动到所有其他选项卡之上突然使 TextAreas 准时实例化。很奇怪,因为所有组件肯定都在创建;我可以看到他们。