您应该将视图元素中的 tabBarVisible 属性设置为 false,然后在登录后更改它,如下所示:
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
tabBarVisible="false"
title="My View" />
当您想要显示视图时,只需通过将 this.tabBarVisible 设置为 true 来让您的函数显示栏。
public function loginHandler():void {
// Do login activities
this.tabBarVisible = true;
}
这是我在评论中提到的...
主要.mxml:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:components="components.*"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private static var app:Main;
public static function login():void {
app.loginComponent.visible = false;
app.navigator.visible = true;
}
protected function creationCompleteHandler(event:FlexEvent):void {
app = this;
}
]]>
</fx:Script>
<components:LoginComponent id="loginComponent" left="0" right="0" top="0" bottom="0" />
<s:TabbedViewNavigator id="navigator" left="0" right="0" top="0" bottom="0" visible="false">
<s:ViewNavigator id="testView1" width="100%" height="100%" label="Test 1" firstView="views.TestView1" />
<s:ViewNavigator id="testView2" width="100%" height="100%" label="Test 2" firstView="views.TestView2" />
</s:TabbedViewNavigator>
我在这里所做的是创建一个默认应用程序,其中包含一个简单的登录组件,如下所示......
登录组件.mxml:
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
protected function login(event:MouseEvent=null):void {
Main.login();
}
]]>
</fx:Script>
<s:VGroup left="0" right="0" top="0" bottom="0" horizontalAlign="center" horizontalCenter="0"
verticalAlign="middle" verticalCenter="0">
<s:HGroup left="0" right="0" height="75" horizontalAlign="left" verticalAlign="middle">
<s:Label text="User Name"/>
<s:Spacer width="10" height="10"/>
<s:TextInput id="usernameInput" width="200"/>
</s:HGroup>
<s:HGroup left="0" right="0" height="75" verticalAlign="middle">
<s:Label text="Password"/>
<s:Spacer width="18" height="10"/>
<s:TextInput id="passwordInput" width="200" displayAsPassword="true" enter="login()"/>
</s:HGroup>
<s:HGroup left="0" right="0" height="75" verticalAlign="middle" horizontalAlign="center" gap="20">
<s:Button label="Login" click="login(event)" id="btnLogin"/>
</s:HGroup>
</s:VGroup>
这使我可以拥有一个我刚刚在组件中创建并作为启动屏幕嵌入到主应用程序中的登录屏幕,并且可以随意显示/隐藏 TabbedViewNavigator。我还没有尝试使用从一个应用程序启动到下一个应用程序来查看状态是如何维护的(即,如果您想要持久登录,您可能可以在创建完成处理程序中进行一些验证,但这取决于您观点)。