3 Replies Latest reply on May 16, 2010 10:48 PM by BhaskerChari

    change base view state from a custom component

    dasun1981 Level 1

      I'm pretty new to flex and I'm having a small issue in change the view state from a component.

       

      My Application have 2 custom components called userlogin and main menu. In the main application page I have userlogin component in one state and the main menu component in another. I'm trying to change the state if the login in successful from user login to main menu. I have the following function written inside the login component.

       

      private function IsUserLoggedIn(evt:ResultEvent):void
                  {
                      if (evt.result.islogin.toString() == "true")
                      {
                          currentState = "MainMenu";
                      }
                      else
                      {
                          Alert.show("Login failed, please try again.", "Login Failed");
                      }
                  }

       

      This code worked when I had all the controls in the main page. But then I created components and included them in to components and now when the login is success, its giving the following error.

       

      ArgumentError: Undefined state 'MainMenu'.
          at mx.core::UIComponent/getState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UI Component.as:9908]
          at mx.core::UIComponent/findCommonBaseState()[E:\dev\4.0.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9928]
          at mx.core::UIComponent/commitCurrentState()[E:\dev\4.0.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:9750]
          at mx.core::UIComponent/setCurrentState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:9701]
          at mx.core::UIComponent/set currentState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:6087 ]
          at components::UserLoginForm/__btnSubmit_click()[C:\Projects\WarrantyAutomation\src\componen ts\UserLoginForm.mxml:60]

       

      I'm sure this has something to do with accessing the states from a custom component, but I do not know how to change the state to the main menu. Please help me with this. Any help is greatly appriciated.

        • 1. Re: change base view state from a custom component
          BhaskerChari Level 4

          Hi dasun1981,

           

          private function IsUserLoggedIn(evt:ResultEvent):void
                      {
                          if (evt.result.islogin.toString() == "true")
                          {
                              currentState = "MainMenu";
                          }
                          else
                          {
                              Alert.show("Login failed, please try again.", "Login Failed");
                          }
                      }

           

          If I am right the above function is in your userlogin component and the two components "userlogincomponent" and "maincomponent" are in main application file and the states were also defined in main application file.

           

          But in the function above the currentState refers to the state of the userlogin component and not the main application ...but the states are defined in main application file...that's the reason why the exception was thrown...

           

           

          Instead you replace the line in the above function with the below line:

           

          Application.application.currentState = "MainMenu";

           

           

          Please mark it as answer if it helped you.

           

          Thanks,

          Bhasker Chari

          1 person found this helpful
          • 2. Re: change base view state from a custom component
            dasun1981 Level 1

            Thanks for the quick response. However since I was using the newer version, the exact code you mentioned did not worked as that class library has been discontinued. But your answer led to me the correct one, which is the FlexGlobals.topLevelApplication.currentState.

             

            Again thanks alot.

            • 3. Re: change base view state from a custom component
              BhaskerChari Level 4

              Thanx..I am glad it helped you...

               

              All the best for rest of your project.

               

              Thanks,

              Bhasker Chari