3

I'm trying to build an app with Login view (no tabs), after user submits "Login" it'll then switch to another Main view (with tabs). Is this possible?

Currently I chose the "Tabbed Application" under the Application Template.
To make the tab bar hidden I tried:

protected function view1_activateHandler(event:Event):void
        {
            // TODO Auto-generated method stub
            this.tabBarVisible = false;
        }

..but the hide has a slide-down animation upon running the app (meaning its not instantly hidden)
Plus if the switched to the Main view, the Login Tab (which belongs to LoginView) button will on the tab bar which I do not want.

Is there another way? I'm pretty new to Flash Builder/Flex 4.5.. Help

I need 10 reputation points to post images =.= Sorry I wanted to post screenshots for better understanding. 4 more points to go ):

daney
  • 83
  • 1
  • 6

1 Answers1

5

You should set the tabBarVisible property in the view element to false and then change it after login as follows:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    tabBarVisible="false"
    title="My View" />

When you want to show the view, just have your function show the bar by setting this.tabBarVisible to true.

public function loginHandler():void {
    // Do login activities
    this.tabBarVisible = true;
}

Here's what I referred to in my comment ...

Main.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>

What I've done here is create a default application which contains a simple login component as follows ...

LoginComponent.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>

This allows me to have a login screen which I've just created in a component and embedded in the main app as a launch screen and the TabbedViewNavigator can be shown/hidden at will. I haven't tried using from one app launch to the next to see how state is maintained (i.e. if you want to have a persistent login, you might be able to do some verification in the creation complete handler, but that's on you at this point).

Chad
  • 890
  • 6
  • 20
  • The first part works thanks Chad! But because I added a tab view "Login", the tab button belonging to it appears at the tab bar on the Main view (after successful login). I can't seem to find a way to remove it. Is it because everything is wrapped under ? Does having different states work in any way? I tried playing around that though :P – daney Aug 24 '11 at 02:09
  • Oh, don't add a TabView named login. Here's what you can try. I would create a base application, not a Tabbed one and manually create a TabbedViewNavigator section. You can then build a login component and put it on top of whatever is on the screen. You then show/hide the component and show/hide the TabbedViewNavigator and launch the first view upon a successful login. I'll add some additional code to my answer to demonstrate. – Chad Aug 29 '11 at 14:54
  • Thanks i'll give it a try. I decided not to use the Tabbed view for now. Currently I'm using the view-based application template to switch from "Select Domain" > "Login" > "Main view". The rest of the subsequent views I used only the List component [ example >> `protected function list_changeHandler(event:IndexChangeEvent):void { //"Navigate and pushing DomainID (data) to the next view" navigator.pushView(views.LoginView, list.selectedItem.DomainID); }` But it'll be good to explore more and I look forward to your solution Chad (: – daney Aug 31 '11 at 02:55
  • Sure, no problem, I'm happy to help! :) I actually had to figure this one out to use in my own app, so I like to spread what I've learned around. If you have an additional question regarding your new approach, I'd love to help if you want. Just post another question and I'll see if I can help. – Chad Sep 01 '11 at 17:22
  • Thanks Chad! I've tried your suggestion for fun. Will use it as reference for future projects! Easy to understand (: By the way is it possible to implement a transition from Login to the Main View? Cos currently the switch of view appears to be abrupt. I tried adding a busy indicator before switching to Main though LOL! (I'm such a flex newbie honestly) Or should I post another fresh question about this? Haha! Thanks! – daney Sep 06 '11 at 02:39
  • I'd post a fresh question about this one. You can probably do a transition, but I haven't bothered to get that far in it as I'm not at a stage where I am cleaning up and doing those small visual things in my app yet. – Chad Sep 06 '11 at 17:18
  • I just thought of something regarding transitions: you could probably have multiple states in your main application, one containing the login form and the other containing your tab view navigator (or view navigator for a non-tabbed app) and put the transition on the switch between the states. You could then just switch states rather than switching the visible flag on the components. – Chad Sep 07 '11 at 13:37
  • Alright! The transitions part isn't that important at the moment now anyway. Just a thought that's all haha! Thanks for the suggestion Chad! By the way have you heard of "eskimo"? I find it pretty cool, an open source flex mobile library: [Eskimo](http://e-skimo.com/). Not sure if you knew about that site, but just to share with you what I (just) found (: – daney Sep 08 '11 at 06:46