5 Replies Latest reply on Aug 13, 2011 12:17 AM by Flex harUI

    Flex 4.1 Why do I have to declare my Interfaces in the main app?

    FM_Flame Level 1

      Why do I have to declare my Interfaces in the main app when I am using the interface in a modular system meaning that my main app loads a module which loads a module. So the last module has the interface, I want to declare the interface in the first module loaded and pass it's moduleFactory to the second (last) module, but then the Interface(module) is null.

       

      Why is this happening and is it possible not to declare the Interface in the main app but in the first module for use in the second module ?

        • 1. Re: Flex 4.1 Why do I have to declare my Interfaces in the main app?
          Flex harUI Adobe Employee

          If you don't use an interface, you are linking the modules classes into the

          loading SWF, defeating the point of modules.  The compiler may not detect

          that you are doing that in a module, but the same problem exists.

          • 2. Re: Flex 4.1 Why do I have to declare my Interfaces in the main app?
            FM_Flame Level 1

            If you don't use an interface, you are linking the modules classes into the

            loading SWF, defeating the point of modules.

            I know that, that's why I am using interfaces for module to module communication.

             

            The compiler may not detect

            that you are doing that in a module, but the same problem exists.

            not sure what u mean here.

             

            So basicly my main app loads module1 which loads module2. Module2 implements IModule2 interface. Module1 casts module2 to IModule2 interface and uses it's functions. When I do this I get error cause IModule2(module2) is NULL, unless I declare the interface in the main app like this;

             

            import IModule2; IModule2;

             

            But I don't want to declare anything in the main app, I want the module1 and module2 to be used independantly from the main app, which looks impossible to me at this point since I have to declare the interface, which module1 uses to communicate to module2, in the main app.

             

            Is there any way around this?

            • 3. Re: Flex 4.1 Why do I have to declare my Interfaces in the main app?
              Flex harUI Adobe Employee

              Did you specify the module1's applicationDomain in the load?  The default

              will be the main app's appDom which might be messing things up.

              • 4. Re: Flex 4.1 Why do I have to declare my Interfaces in the main app?
                FM_Flame Level 1

                NIIIIIIIIICEEEEEEEEEE

                 

                Ok so I got this working perfeclty, thanks! I just got one question - why would I use the main app's application domain by default, I mean when I switched it now to use the module1's application domain what did I do?

                 

                Here is how I did it:

                 

                var currentDomain:ApplicationDomain = moduleFactory.info()["currentDomain"];
                var moduleApplicationDomain:ApplicationDomain = new ApplicationDomain(currentDomain);
                pvGalleryAlbumContentModuleInfo.load(moduleApplicationDomain,null,null,moduleFactory);

                 

                And why it didn't work before?

                 

                I guess I should read AGAIN about application domains to follow up the logic here, but if you could explain it in short that would be cool

                • 5. Re: Flex 4.1 Why do I have to declare my Interfaces in the main app?
                  Flex harUI Adobe Employee

                  It is because ModuleManager is linked into the main application so even if

                  your module code calls ModuleManager, the ModuleManager's ApplicationDomain

                  becomes the default while the ModuleManager's code is running.

                   

                  We made this less error-prone in 4.5