5 Replies Latest reply on Aug 8, 2008 11:36 AM by alice_data

    Mx:States Add Child Issues

    alice_data Level 1

      I have a scenario here where I would like to have the user log in, and have two different outputs based on the transitioned state after the log-in process completes. Since my application links to an external data source using HTTPService in the back end using PHP, I want the output of the state to show only the error message if the user does not log in correctly and sees nothing else further that comes from the DataGrid format since no data would be returned from the database if the user logs in inaccurately.

      This is the portion of my state:

      <mx:AddChild relativeTo="{loginForm}" position="lastChild">
      <mx:DataGrid id="patient_find" dataProvider="{srv.lastResult.logged_in.mydata}" width="250" height="100">
      <mx:DataGridColumn headerText="ID" dataField="id" textAlign="center" width="78"/>
      <mx:DataGridColumn headerText="Name" dataField="name" textAlign="center" width="75"/>
      <mx:DataGridColumn headerText="Sex" dataField="sex" textAlign="center" width="45"/>
      <mx:DataGridColumn headerText="Age" dataField="age" textAlign="center" width="45"/>

      How can I make this segment above display only when the user has logged in correctly?
      Anything is appreciated.

        • 1. Re: Mx:States Add Child Issues
          Gregory Lafrance Level 6
          There are probably many ways to do this, but to me, if the user did not successfully login, just popup a message telling them so, and keep them at the login screen, and change no states.
          • 2. Re: Mx:States Add Child Issues
            alice_data Level 1
            My problem is that when users log in, I thought that we are supposed to have it change to a different state so that it can display a different message on the screen. If the state does not change, how is the application be able to proceed to search and check for the "validity" of the input?

            Is there an example somewhere where you could lead me to see what you mentioned in the previous message?

            Many thanks.
            • 3. Re: Mx:States Add Child Issues
              Vanden_B Level 1
              Use states like:
              <mx:State id="FaultState" name="FaultState">
              <mx:AddChild relativeTo="{loginForm1}" position="lastChild">
              <mx:Text id="fault" text="Error text" />

              and functions to set the state like:

              private function loginFault():void {
              currentState = "FaultState";

              A mix of these basics will help
              • 4. Re: Mx:States Add Child Issues
                Gregory Lafrance Level 6
                I would think your login code would be in a self-contained login component.

                That component can be displayed, and it can communicate with whatever is used to verufy the login, such as a server or database.

                That component can also popup an alert if the login fails.

                Only if login succeeds, once again performed right there within the login component, then the login component can set a global variable in the main app to true (meaning successful login), and perhaps also dispatch a custom event.

                The main app, when handling that custom event, can check that the global variable is true (meaning successful login), and change the state.

                Keep things self-contained component based, event based, and reduce complexity.
                • 5. Re: Mx:States Add Child Issues
                  alice_data Level 1
                  Thanks for the help, guys. I have successfully set 2 variables to switch back and forth to determine how to display the error or confirmation message.