【问题标题】:Changing state TextArea.setText not work in a navigator, null reference更改状态 TextArea.setText 在导航器中不起作用,空引用
【发布时间】:2014-01-03 01:12:36
【问题描述】:

我正在设计一个聊天应用程序,并决定使用状态。

但是在切换到另一个状态后,TextArea.setText 在 navigatorContent 中不起作用,(对对象的空引用)。

在 navigatorContent 之外,代码工作正常。

(第一阶段模拟登录窗口,第二阶段为客户端/服务器的消息区。)

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       width="304" height="283">
    <fx:Script>
        <![CDATA[


            protected function changeState(event:MouseEvent):void{

                // change state
                setCurrentState("State2");

                // set text
                appendText("Hello world");
            }

            private function appendText(msg:String):void{
                textArea1.text = msg;
            }

        ]]>
    </fx:Script>
    <s:states>
        <s:State name="State1"/>
        <s:State name="State2"/>
    </s:states>

    <s:Button includeIn="State1" label="State 2" click="changeState(event)" horizontalCenter="0"
              verticalCenter="0"/>
    <mx:TabNavigator includeIn="State2" x="0" y="0" width="100%" height="100%">
        <s:NavigatorContent width="100%" height="100%" label="Tab 1">
            <s:TextArea id="textArea1" x="0" y="0" width="100%" height="100%"/>
        </s:NavigatorContent>
    </mx:TabNavigator>
</s:WindowedApplication>

【问题讨论】:

  • 好吧,您确实只在State2 中包含了TabNavigator(以及它的子项,包括TextArea)。所以在State1 中没有textArea1。无需多言:这是预期行为。
  • 我是这么认为的,但很少在 TabNavigator 之外工作,仅包含在阶段 2 中的 textArea

标签: apache-flex textarea nullreferenceexception navigator


【解决方案1】:

这行得通,将 TabNavigator 上的 creationPolicy 属性设置为“all”。

【讨论】:

    猜你喜欢
    • 2014-08-22
    • 2016-08-04
    • 2018-08-09
    • 2015-11-17
    • 2019-08-26
    • 2021-07-21
    • 1970-01-01
    • 2018-07-22
    相关资源
    最近更新 更多