Hello All,

I was trying to create a login Page. The page has one main MXML application 
file with couple of MXML components. The First component contains the following:

Component1.mxml:

<?xml version="1.0" encoding="utf-8"?>

    width="60%" height="261">

    <mx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;
            import mx.controls.Alert;
            import components.LoginPopUp;
            import mx.events.CloseEvent;
            
            public var loginWin:LoginPopUp;
            
            private function loginHandler():void {
                loginWin = new LoginPopUp();
                loginWin.addEventListener(CloseEvent.CLOSE,closeHandler);
                PopUpManager.addPopUp(loginWin,this,true);
                PopUpManager.centerPopUp(loginWin);
            
            }
            
            public function closeHandler(event:CloseEvent):void
            {
                PopUpManager.removePopUp(loginWin);
                
            }
            
        
                public function checkCredentials():void{
                
                if(loginWin.userInput.text=='funandlearning' && 
loginWin.passwordInput.text=='funandlearning')
                {
                    Alert.show("Login Successful");
                    
                }
                else
                {
                    Alert.show("Login Failed");
                }
            }
            
        
        ]]>
    </mx:Script>


    
    <mx:HBox width="90%" height="55" borderColor="#F85023" id="headerButtons"
        borderStyle="outset" horizontalAlign="left" verticalAlign="middle"
        backgroundColor="#938480">
        <mx:Spacer width="10%"/>
        <mx:Button id="loginMain" label="Login" click="loginHandler()"/>
        <mx:Button id="logout" label="LogOut" />    
    </mx:HBox>
    
    <mx:HBox width="100%" height="82%">
        <mx:HBox width="25%" height="82%" borderStyle="outset" 
borderColor="#F85023">
        </mx:HBox>
        <mx:HBox width="65%" height="82%" borderColor="#F85023" 
borderStyle="outset">
        </mx:HBox>
    </mx:HBox>
</mx:VBox>

component2.mxml has the following code for the popup

<?xml version="1.0" encoding="utf-8"?>

                xmlns:main="components.*" layout="vertical"
          title="Please login" showCloseButton="true">
    
    <!-- defined state to toggle between register and login -->
    <mx:states>
        <mx:State name="Register" basedOn="">
            <mx:AddChild relativeTo="{loginForm}"
                         position="lastChild" creationPolicy="all">
                <mx:FormItem label="Email">
                    <mx:TextInput id="email"/>
                </mx:FormItem>
            </mx:AddChild>
            
            <mx:SetProperty target="{loginButton}" name="label" 
value="Register"/>
            <mx:RemoveChild target="{registerLink}"/>
            
            <mx:AddChild relativeTo="{linkSpacer}" position="before">
                <mx:LinkButton label="Return to Login" 
click="currentState='';this.title='Please Login'"/>
            </mx:AddChild>            
        </mx:State>
    </mx:states>
    <mx:Script>
        <![CDATA[
            import mx.events.CloseEvent;
            import mx.managers.PopUpManager;
            import mx.controls.Alert;
            
        
        ]]>
    </mx:Script>
    <mx:Form id="loginForm">
        <mx:FormItem label="Username:">
            <mx:TextInput id="userInput"/>
        </mx:FormItem>
        <mx:FormItem label="Password:">
            <mx:TextInput id="passwordInput" displayAsPassword="true"/>
        </mx:FormItem>
    
    </mx:Form>
    <mx:ControlBar>
         <mx:LinkButton 
            label="Need to Register?" id="registerLink"
            click="currentState='Register';this.title='Register'"
        />
        <mx:Spacer width="100%" id="linkSpacer"/>
        <mx:Button label="Login" id="loginButton" click="checkCredentials()"/>
        <mx:Button label="Cancel" click="PopUpManager.removePopUp(this)"/>
    </mx:ControlBar>
    
</mx:TitleWindow>

I need help in knowing how to change the login button in component1.mxml to 
logout button when the login functionaility from the popuup window is successful

Thanks.



      

Reply via email to