6 Replies Latest reply on Feb 27, 2008 2:15 PM by ericbelair

    Help with Dynamic Dashboard Application

    ericbelair Level 1
      I have been developing in Flex for a few months now. I have created a dynamic Dashboard/Mashup application using Flex. However, I have one small problem. As new sub-applications are made available for this application, I have to edit the MXML files and recompile. I am wondering if anyone has any good ideas on how to facilitate this type of dynamic application/sub-application architecture.

      Right now, I basically have 3 sub-applications - let's call them App1 (App1.mxml) which is a DataGrid, App2 (App2.mxml) which is a Line Chart, and App3 (App3.mxml) which is a Pie Chart. A user can put one, two, or all three sub-applications on the page, so it has to be built dynamically. I retrieve their layout from the database via a WebService, then loop through the collection of sub-applications they have saved. To accomplish this, I do somethign similar to what is displayed in the attached code.

      This works exactly how I need it to. However, if I want to create a new sub-application - say App4 as an Advanced DataGrid - I have to edit this code to add a new Case statement for it, and then recompile. I'd like to avoid that.

      Any help would be greatly appreciated.

      Thanks.
        • 1. Re: Help with Dynamic Dashboard Application
          SujitG Level 2
          Try the web tier compiler. You can find more details in this url
          http://livedocs.adobe.com/labs/flex3/html/apache_1.html
          Hope this helps
          • 2. Re: Help with Dynamic Dashboard Application
            ericbelair Level 1
            Thank you SujitG. That is interesting, but, compiling the file is not the real issue. I know that I am going to recompile my MXML for every edit I make. I am really just trying to find a way to program the application so I will not need to edit the MXML every time I need to add a subcomponent. If anyone else has any suggestions, please let me know.

            Thanks again.
            • 3. Re: Help with Dynamic Dashboard Application
              cxf02 Level 1
              This may be more than you are looking for, but try looking at an Abstract Factory pattern to produce variations of the same object. See "Head First Design Patterns" for a good implementation example or for advanced implementations with other design patterns see "Core J2EE Patterns: Best Practices and Design Strategies, Second Edition".

              The Cannon of Object Oriented Design has three tenents: Inheritance, Encapsulation and Polymorphism. Using design patterns to solve OO problems such as what you describe will unleash the real power behind AS3. If you already understand what I'm speaking about, then please accept my apologies. Because of the question, I'm unsure as to your qualifications in OO design.

              Another way to do this might be create an interface and implement it within all your child classes. Then code using the interface instead of the implementation. In java, (and it should work the same in AS3) by supplying the concrete class name to instantiate at runtime, and then invoking the methods of the interface, you have designed in polymorphic behaviors for runtine vs. compiletime. I have yet to do this in AS3, so hopefully, it should work the same.

              Cheers,


              • 4. Re: Help with Dynamic Dashboard Application
                ericbelair Level 1
                Thanks Curtis. I will definitely do more research based on what you have shared. My OO experience is very limited - about 4-5 months (I've been developing CF/SQL for the past 7 years).

                Thanks again.
                • 5. Re: Help with Dynamic Dashboard Application
                  wouter vdb Level 1
                  You can eliminate this particular switch by providing the 'qualified' class name in the service. These names are what you get from the getQualifiedClassName function. Given such name you can use the getDefinitionByName function to get the class, which you can then instantiate, as in:

                  var appClass:Class = getDefinitionByName(appClassName);
                  var app:App = new appClass();

                  However, the getDefinitionByName function needs to be able to effectively find the (compiled) class in the swf. So whenever you write a new application class you will need to import that class and recompile anyway.

                  ps: You will definitely profit from learning more about design patterns...

                  • 6. Help with Dynamic Dashboard Application
                    ericbelair Level 1
                    Hi Wouter.

                    Thank you for the suggestion. I've almost got this working. I tried running similar code inside one of my case statements, as follows, and it works:

                    private function createComponent():void
                    {
                    switch (componentClassName)
                    {
                    case "app1":
                    var componentClass:Class = getDefinitionByName(componentClassName) as Class;

                    var component:componentClass;

                    component = new componentClass();

                    viewStack.addChild(component);

                    break;
                    }
                    }

                    However, when I pull this code out of the switch/case, I get an error when I try to compile:

                    private function createComponent():void
                    {
                    var componentClass:Class = getDefinitionByName(componentClassName) as Class;

                    var component:componentClass;

                    component = new componentClass();

                    viewStack.addChild(component);
                    }

                    ...results in compilation error: "1046: Type was not found or was not a compile-time constant: componentClass.".

                    Why would this work inside the switch/case, but not outside of it?

                    Thanks.