10 Replies Latest reply on Aug 29, 2008 11:32 PM by Ratsnackbar

    Problems Accessing Modules from Tab-Navigator and Buttons

    elfenix451
      I have a multiple module project that I am starting. I have all the modules listed at the top in a tab navigator and they all work. But on several modules I will also have buttons that need to link to other modules for quick access.

      What's the best way to code this? I've gotten it to a point so that when I click on a button nothing happens.

      Any help would be appreciated.

      mainMenu.swf
        • 1. Re: Problems Accessing Modules from Tab-Navigator and Buttons
          jpsoul Level 1
          What are you trying to do with your module once you load it? In your code I only see the call to load the module. I don't see how the module is used.

          If you are using the module as a DisplayObject, maybe try assigning it to a var and (once it's loaded) manipulate it like any other DisplayObject.

          • 2. Re: Problems Accessing Modules from Tab-Navigator and Buttons
            Level 7

            "elfenix451" <webforumsuser@macromedia.com> wrote in message
            news:g91o90$p2e$1@forums.macromedia.com...
            >I have a multiple module project that I am starting. I have all the
            >modules
            > listed at the top in a tab navigator and they all work. But on several
            > modules
            > I will also have buttons that need to link to other modules for quick
            > access.
            >
            > What's the best way to code this? I've gotten it to a point so that when
            > I
            > click on a button nothing happens.

            http://blogs.adobe.com/flexdoc/pdfs/modular.pdf


            • 3. Re: Problems Accessing Modules from Tab-Navigator and Buttons
              yigitt Level 1
              If I were you, I would implement a menu manager which controls which module to show. I would also implement a static enumaration class which will keep some event names including module names.
              Then if a module wants to trigger the opening of another module, it will just dispatch an event. the event will be caught by the menu manager and the proper action will be done. If i were you, I would also override the tabNavigator to give complete control to menu manager(it might be needed in the future)

              yigit
              • 4. Re: Problems Accessing Modules from Tab-Navigator and Buttons
                Ratsnackbar Level 2
                To me it sounds like you might want to check out one of the many Flex IOC Frameworks available. You would perhaps dynamically register your modules on load with the framework for events they want to be notified of and bypass the standard event system.

                You may also want to look into the Mate framework. I have not tried it with modules but intend to soon and have hopes that it will assist in this type of situation as I too have run into similar problems using Reflection in Flex and am tired of creating my own frameworks to solve them.
                • 5. Re: Problems Accessing Modules from Tab-Navigator and Buttons
                  elfenix451 Level 1
                  Thanks for the suggestions.

                  The modules will work much like different pages in a website. We are converting from a PHP/MYSQL site to a flex site.

                  Do you have any links for the IOC or Mate Framework? I am fairly new to flex development and trying to learn as much as I can from this project.
                  • 6. Re: Problems Accessing Modules from Tab-Navigator and Buttons
                    jpsoul Level 1
                    I agree that you are probably going to want to use events to drive this. And those events will most likely be dispatched by your links, and handled by some object that updates the display of your application.

                    I wonder if using modules adds unneeded complexity...how many separate components are you using? Do they all need to be loaded separately?

                    While modules offer a decent way to optimize loading, I wonder if you should at first think of your architecture without them in order to see how the pieces fit together. Once you get that, then maybe consider optimizing with modules.
                    • 7. Re: Problems Accessing Modules from Tab-Navigator and Buttons
                      jpsoul Level 1
                      I also think that using another framework may also add more unneeded complexity at this point...especially if you are still trying to get familiar with Flex. Adding another framework would add learning curve to deal with. You may end up wanting one, but I would explore what Flex has to offer first.
                      • 8. Re: Problems Accessing Modules from Tab-Navigator and Buttons
                        elfenix451 Level 1
                        Well the reason that I'm looking into using modules is that it will be a fairly large program with a lot of processing. We are moving away from PHP/MySQL because it is already to slow with a lot of back-end processing. There's going to be at least 11 main areas in the program with many main areas having sub-area's also.

                        If you don't think modules is the way to go what are some other options for moving between areas in the site.
                        • 9. Re: Problems Accessing Modules from Tab-Navigator and Buttons
                          jpsoul Level 1
                          So, if I have this right you are using modules to represent the pages in your web site. Each module represents a page. A module inherits from a Container/UIComponent/Sprite. The functionality that you get from a module that you don't get from a Container is that it can be compiled into a swf (and the compiling can be optimized to reduce the file size).

                          So, looking at it from this perspective you have two areas of concern: how to use the modules effectively for loading and how to use the Containers effectively to layout your application (web pages).

                          I would tackle the second issue first. In that I would create my application to use Containers (or some subclass like Canvas) to layout my web pages. So, you may want to create custom components that extend Container and add the functionality you want for that Container. In your original code sample you would change the root tag from Module to Container (or some subclass like Canvas) and remove the module loading code. Then you can structure your application to use these Containers. So, your application will be creating new YourContainer() or referencing your custom Container component via MXML. <myNS:MyContainer />. I prefer working in AS rather than MXML so I would probably use "new" to create the custom component when needed. It also makes it easy to change this strategy if you then decide to use modules to optimize.

                          In any case, I would solve the navigation between web pages first before optimizing with modules. You have many options. You could use states ( http://livedocs.adobe.com/flex/201/langref/mx/states/State.html) or you could just use a Container (I'll call it MainContentArea) to hold the custom Container web pages you are building. Anytime you want to update the page being displayed you can add the new web page (one of your custom containers) to the MainContentArea display list and remove the old web page (one of your custom components that the user is navigating away from) from the MainContentArea. You can update the content on the click handler for a button like this:

                          private function handleClick(e:Event):void
                          {
                          var oneOfMyWebPages:OneOfMyWebPages = new OneOfMyWebPages(); / create new page
                          MainContentArea.removeChildAt(0); // remove old page - assuming there is only 1 child on the display list
                          MainContentArea.addChild(oneOfMyWebPages); // add new page to display list
                          }

                          Note: for that to work you need to have a reference to the MainContentArea. As long as you have that reference, you can update that area. There are many ways to orgize the code, but that is the essential part.

                          So, I would figure out all that navigation stuff first before tacking modules. Then, if you still want to use modules it will be much easier to implement them (Although you should research all the potential drawbacks of them like you can't share them between applications with divergent class dependencies).

                          I hope that helps.

                          • 10. Re: Problems Accessing Modules from Tab-Navigator and Buttons
                            Ratsnackbar Level 2
                            HI, sorry I did not get back to this sooner. The link to Mate would be http://mate.asfusion.com and it is very well documented.

                            Mate is jokingly said to be a framework for people who do not like frameworks. I found it to be an easy way to keep things organized for medium sized projects.

                            I normally do not like most frameworks but Mate is different. This is one framework I suggest even to those who are new to Flex as long as the person is not new to good coding practices and OOP in general.

                            It will especially appeal to anyone who is used to ColdFusion development because it's use is mxml tag based and so will seem more at home with the way most things in CF are done.