1
我設計一個聊天應用程序無法正常工作,並決定使用的狀態。改變狀態TextArea.setText在導航,空引用
但切換到另一個狀態後,TextArea.setText不能在navigatorContent內部工作,(null引用對象)。
出於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'。沒什麼可說的:這是預期的行爲。 – RIAstar
我是這麼認爲的,但很少做與TabNavigator外僅包括在第二階段的
Joseph