1

我在一个相当简单的应用程序中使用 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 准时实例化。很奇怪,因为所有组件肯定都在创建;我可以看到他们。

4

1 回答 1

4

这是因为 TextArea 位于 TabNavigator 的一个不是第一个子级的子级中,所以默认情况下,直到用户打开该选项卡才会实例化它。

您的选择是等到用户打开该选项卡以执行您需要做的任何事情来设置 TextArea 或更改 TabNavigator 上的子创建策略以在启动时创建其所有子项,而不是等待它们被单击。

为此,您需要将 TabNavigator 上的 creationPolicy 属性设置为“all”。

于 2010-06-11T23:53:23.883 回答