我在使用 TabNavigator 时遇到问题,它总是发送错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.containers::TabNavigator/keyDownHandler()[/Users/justinmclean/Documents/ApacheFlex4.11.0/frameworks/projects/mx/src/mx/containers/TabNavigator.as:903]
示例代码:
<?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" applicationComplete="init(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function init(event:FlexEvent):void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
}
public function handleKeyDown(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.F1){
if(currentState=="State1"){
currentState = "setting";
}else{
currentState = "State1";
}
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:states>
<s:State name="State1"/>
<s:State name="setting"/>
</s:states>
<s:BorderContainer left="0" right="0" top="0" bottom="0" includeIn="setting">
<mx:TabNavigator id="TabNavigator" left="10" right="10" top="110" bottom="10" creationPolicy="all">
<!-- General Tab -->
<s:NavigatorContent id="generaltab" width="100%" height="100%" label="General">
<s:Group id="generalcontainer">
</s:Group>
</s:NavigatorContent>
<!-- Screen Tab -->
<s:NavigatorContent id="screentab" width="100%" height="100%" label="Screen">
<s:Group id="screencontainer" width="100%" height="100%">
</s:Group>
</s:NavigatorContent>
<!-- Playlist Tab -->
<s:NavigatorContent id="playlisttab" width="100%" height="100%" label="Playlist">
<s:Group id="playlistcontainer">
</s:Group>
</s:NavigatorContent>
</mx:TabNavigator>
</s:BorderContainer>
</s:WindowedApplication>
当我按 F1 时,它会跳转到设置页面。这将显示选项卡导航器。再次按 F1 将其隐藏。
基本上,重复显示和隐藏选项卡导航器是没有问题的。但是,如果我在隐藏选项卡导航器之前单击任何选项卡,当我尝试通过按键盘上的 F1 再次显示选项卡导航器时,它会发送错误,如上所示。
如何解决/防止错误发生?
谢谢你。