3 Replies Latest reply on Jan 15, 2013 5:29 PM by Captain825

    Multiple States v. Viewstack

    Captain825 Level 1



      Kinda new to programming in Flex 4.6 but I would appreciate some comments on my line of thinking.


      I am developing an application that has a menu at the top of a view state with 10 different choices.  When a user clicks on a choice, I change to the appropriate State that holds the appropriate form.  The same menu is also displayed at the top of the new State.  I took a look at the code and realized that it created an enormous amount of duplicate code to have ten States with ten of the same menus at the top which seems very inefficient to me.


      I am now thinking I should have a single State with a ViewStack with each viewstack container being a seperate form depending on which button the user clicks on the menu.


      Keeping in mind that I am relatively new, would using viewstacks in this situation be the most efficient?


      Thanks in advance.

        • 1. Re: Multiple States v. Viewstack
          jfb00 Level 3


          I was having the same issue long time ago until i discover modules.

          Please take a look at this:



          It is not an easy subject but try and see if you can use modules.

          I hope this help.

          1 person found this helpful
          • 2. Re: Multiple States v. Viewstack
            jfb00 Level 3

            I created a simple example that may help you and others to understand.


            <?xml version="1.0"?>

            <!-- modules/StyleModLoaderApp.mxml -->














                        private function init():void{

                            myMenuBar.addEventListener(MouseEvent.CLICK, openMenuItem_click);



                        protected function openMenuItem_click(evt:MouseEvent):void {

                            var tempIndex:Object  = evt.currentTarget;

                            if (tempIndex.selectedIndex != -1){

                                switch( tempIndex.selectedIndex ){

                                    case 1:

                                        myModule.url = "moduleA.swf";


                                    case 2:

                                        myModule.url = "moduleB.swf"










                <mx:MenuBar id="myMenuBar" labelField="@label" >


                        <menuitem label="MenuItem A">

                            <menuitem label="SubMenuItem A-1" enabled="false"/>

                            <menuitem label="SubMenuItem A-2"/>


                        <menuitem label="Module A"/>

                        <menuitem label="Module B"/>




                <s:ModuleLoader id="myModule" />



            • 3. Re: Multiple States v. Viewstack
              Captain825 Level 1

              Wow, thank you very much.  You've gone above and beyond and I will digest your example and I'm sure I will be able to understand the concepts.


              Thank you very much