4 Replies Latest reply on Jan 28, 2009 3:13 PM by phillipus_rex

    Return to Base State

    phillipus_rex Level 1
      Hello,

      I have a Flex canvas that contains several buttons. When I click the button it changes to the next state which brings up a custom component that has a panel with buttons on it. One of the buttons should close the panel and return to the original state. The exit button is a blue square and here is the actionscript:

      private function onBlueClick ( event:MouseEvent ):void {
      this.currentState=" ";
      }

      Unfortunately, this gives me an "undefined state" error. Does anyone know how I can return to the base state through the actionscript of a custom component?

      Thanks in advance for any help.
        • 1. Re: Return to Base State
          levancho Level 3
          this.currentState="";

          no space between double quotes.
          • 2. Re: Return to Base State
            phillipus_rex Level 1
            Thank you, but I tried that, and I no longer got the error - however, it did not return to base state either. Could there be something else I am missing?

            I have attached the MXML of the main application as well.
            • 3. Re: Return to Base State
              rtalton Level 4
              the problem is you are calling a state change on your custom component, and it has no states defined. You want to call the base state in the main app (parent app).
              Try something like Application.application.currentState = "";

              Having said that, you should look into simply dispatching an event from the component's button click back to the main app, and have the main app handle the event to switch the state. A component should not be controlling the main app like what you are trying as this will lead to issues where the component is too "tightly-coupled" to the main app.
              • 4. Re: Return to Base State
                phillipus_rex Level 1
                rtalton,

                Thanks very much!

                I used this code:

                private function onBlueClick ( event:MouseEvent ):void {
                this.parentApplication.currentState = '';
                }

                ...and it worked perfectly. I am fairly new to Flex and I am not sure how to send control back to the main application, but I will look into your suggestion and try to figure it out.

                Thanks again.