3 Replies Latest reply on Jul 12, 2011 2:43 AM by mikeyin85

    Why we need State?


      Hi, dear all,  I am reading what's new in flex4 these days, and found the states has some big changes in flex4 rather then flex3, but I can not realize what is the benefits with use states? actually all state does is to add/remove some components, or make some changes on a compnent, but I can even do that with turn on/off the component's visible settings, or change some other properties, so why state?  I know there must be the reason that flex provide the states, and make it more easy to use. can some body give me some prompt abouth this?  Regards, Mike.

        • 1. Re: Why we need State?
          EvyatarBH Level 3

          One of the major benefits that I found was the ability to define different values of properties in different states.

          For example, I have an item-renderer that can be collapsed and expanded, so I defined two states for it and the following settings -

          height.Collapsed="36" height.Expanded="320" 


          The bottom line is that this feature provides a lot of flexibility in a relatively simple syntax.

          1 person found this helpful
          • 2. Re: Why we need State?
            Kumar Pratik Level 1

            With the help of state you can navigate to different screens. Lets have an example:

            We have a login screen and requirement is after login we will check if user is general or admin . for both we have different screen. Now we will make 3 state

            1. Base state for login

            2. genstate for general user

            3. adminstate for admin user


            After login we will check:

            if user is general


            current state = genstate


            if user is admin


            currentstate = adminstate







            Again say in admin state say there is a requiremnt where on click of a button you have to display screen for general user so again you can just use currentstate=genstate on click of button


            Hope this helps you

            1 person found this helpful
            • 3. Re: Why we need State?
              mikeyin85 Level 1

              Thanks for your response EvyatarBH and Kumar Pratik.


              I think in the case EvyatarBH said, yes, it was much easier to set propertie values on differents states.

              If there are lot of state, and the controls always to be different size, then this may replace dozened of if...else..(s)


              For the example Kumar gave out, actually I understood what was the point.

              But I think that may only works when the "general" and "admin" page looks very similar.

              Otherwise we may need to maintains a lot of controls and logics in one component, that will be much difficult I think.

              Not sure if my understanding 100% correct, welcome for more replies.


              Again, thanks for your answers, any better suggestions, please keep on.