3 Replies Latest reply on Sep 27, 2010 4:18 PM by Flex harUI

    Accessing components in a different state

    cwramsey

      There's probably a more elegant way of doing this.

       

      Right now I'm setting certain components to be available in all states, but that means I need to make them visible or invisible depending on the state... which is a pain.

       

      How can I access a component in a different state.

       

      Maybe I'm missing something simple like stateName.component.text or something?

        • 1. Re: Accessing components in a different state
          Flex harUI Adobe Employee

          There's a stateChange event.

           

          However, make sure you have to push data down to the components.  It is

          usually better to have the components pull their own data.

          • 2. Re: Accessing components in a different state
            cwramsey Level 1

            I am currently using this, but I'm getting the error that states that what I'm after doesn't exist... when it clearly does.

             

            Here's that code.

             

            private function stateChangeHandler(e:StateChangeEvent):void {
                 if (e.newState == "State1") {
                      dg.visible = true;
                      optionsPanels.visible = false;
                 } else if (e.newState == "options") {
                      dg.visible = false;
                      optionsPanels.visible = true;
                      if (preferences["searchType"] == 0) {
                           googleLocalChoice.selected = true;
                      } else {
                           yahooLocalChoice.selected = true;
                      }
                      
                      yahooID.text = preferences["yahooAPI"];
                 } else if (e.newState == "notes") {
                      dg.visible = false;
                      optionsPanels.visible = false;
                 } else if (e.newState == "password") {
                      dg.visible = false;
                      optionsPanels.visible = false;
                 }
            }

             

            What I'm having trouble with is in the if e.newstate == "options" - I'm getting the error on yahooLocalChoice, because preferences["searchType"] does not equal 0.

            • 3. Re: Accessing components in a different state
              Flex harUI Adobe Employee

              Handling state changes are tricky because there could be a number of things

              changing and not finalized/validated yet.  Sometimes it is best to wait for

              an updateComplete after the stageChange, but then the user might see

              something adjust on the screen.  You can try forcing calls to validateNow(),

              but that might slow down the state change.

               

              This is one of the reasons pushing down changes may not be the best option.

              Having the view pull data from a central data model may be better.