1 Reply Latest reply on Jul 9, 2010 12:31 PM by Ted Moens

    Application Wide State?

    Ted Moens

      Greetings:

       

      I have an Flex 4 application which contains a viewstack and several custom components.  The problem I am trying to address is that I want all the components to be "aware" of whether the user is logged in or not and possibly also the user's role.

       

      So, a non logged in user is welcome to browse everything, a normal user is allowed to edit stuff (which means access to a bunch of similar buttons on similar screens) and a super-duper user can do even more.

       

      Every approach I can think of is flawed.

       

      1) Create the same set of states for each component, propagate state changes to all components.  Simply seems wrong but it would sure be nice to be able to use the IncludeIn="LoggedIn" in all my components.  If I did this what would be a reccomended way to propagate state to the components?

       

      2) Have all components look at the flexGlobals.toplevelApplication.currentState or parentApplication.currentState and make presentation decisions accordingly. Goodbye reusability - but that is no tragedy as none of these components is likely to be reused in a different context.

       

      3) Don't use states at all and keep some kind of user data in FlexGlobals.toplevelApplication - and have the components all look there.  Again goodbye reusability.

       

      Since my problem is simply to make some buttons appear or diappear in components based on an "application wide" state, is there some other option I have missed?

       

       

      Ted

        • 1. Re: Application Wide State?
          Ted Moens Level 1

          Just as a followup:  I realize that if I duplicated the state specification in all my components (yuck), then in each component I could add in the oh so icky:

           

          BindingUtils.bindProperty(this,"currentState",parentApplication,"currentState");

           

          Then as long as I set the state in the parent application all would work.  Just seems wrong but maybe not terrifically wrong.

           

          This leaves then the problem of duplicationg the state declaration for each component.  I think I understand that the state declarations can not be done programatically, but I am so new to FLex that I can't see how to do this without actually duplicating code.  I would prefer to just define the states in some file and include it everywhere, but I'm not clear on how to do that.

           

          Ted