3 Replies Latest reply on May 21, 2008 6:18 AM by Jeesmon

    Loading Modules from File System in Adobe Air

    JustinBozonier Level 1
      I am developing a test runner for Adobe Air and I need to load unit tests dynamically. How can I load a module from the file system?

      After that how do I call classes within the loaded module?
        • 1. Re: Loading Modules from File System in Adobe Air
          One option is:

          1. Create a TestCase class that extends flexunit.framework.TestCase

          package my.package
          import flexunit.framework.TestCase;
          import flexunit.framework.TestSuite;

          public class MyTest extends TestCase
          public function MyTest(methodName:String=null)

          public static function suite():TestSuite {
          var ts:TestSuite = new TestSuite()
          ts.addTest(new FileTest("test"));

          return ts;

          public function test():void {

          2. Pass the class name to flex compiler using -includes argument


          You can add multiple classes separated by a comma.

          3. Then dynamically instantiate it in TestRunner

          var ts:TestSuite = new TestSuite();
          var Clazz:Object = getDefinitionByName("my.package.MyTest") as Class;

          You can look for class names in a file and instantiate each one inside a loop if you have many classes.
          • 2. Re: Loading Modules from File System in Adobe Air
            JustinBozonier Level 1
            Thanks for the reply Jeesmon!

            What I'd like to be able to do is have my air app running and have the user point to a module on their computer to have it loaded and have its unit tests ran. Given that, the compiler option is an obvious no go.

            I know that Ecmascript is technically feasible of dynamic loading of classes at runtime as well as introspection/reflection but I'm just not sure if Adobe has placed too many security restrictions on the app for it to work this way.
            • 3. Re: Loading Modules from File System in Adobe Air
              Level 1
              May be you can try the technique mentioned in the adobe site by loading module into ApplicationDomain.currentDomain at runtime


              There is also a custom ClassLoader source available at http://flexonrails.net/?p=65 (see comment #1 from Matjaz). I haven't tried it yet but will try it later.