2 Replies Latest reply on Feb 2, 2011 9:50 PM by Dajji

    Dynamically loading classes

    Dajji Level 3

      Hey Experts!

       

      I have a requirement to develop an engine which would allow adding some templates without re-compiling the main engine code. I want to allow vendors to create template classes, place it in the may be a predefined folder, make an entry (fully qualified class name) in the xml file. The engine will instantiate the class when required. The process of engine loading the class should be as follows.

       

      • Engine reads an xml file which contains entry for all the template classes to be loaded.
      • Engine encounters a situation where it dynamically gets to know about a class to be instantiated.
      • It looks at the table retrieved from the xml file for the class name.
      • If it founds the class name, it should be able to instantiate it.

       

      Is RSL a solution? If yes, can anyone briefly tell me how to implement this?

       

      Please let me know if my question is not clear.

        • 1. Re: Dynamically loading classes
          Gaurav J Adobe Employee

          You can compile the classes into an actionscript module, and then you can load that module in ApplicationDomain.currentDomain. After the module is loaded, you can use the ApplicationDomain to get the definition.

           

          -Gaurav

          http://www.gauravj.com/blog

          • 2. Re: Dynamically loading classes
            Dajji Level 3

            @Gaurav

             

            Thanks for the reply. I should have mentioned that I thought of using modules. However, I believe this would be an overhead (I might be wrong). Since I need only simple classes (many of them) to be compiled in one file (Just like a library project output swc) which can be loaded and used when required. I guess module would only compile all the classes if they are referenced. My objective is to keep the process as simple as possible so that other vendors can simply write classes, package them and it should work.

             

            Any thoughts?