24 Replies Latest reply on Oct 7, 2011 12:45 PM by mitz11

    upgrading from 3.5 to 4.5 - module load problem

    mitz11 Level 1

      Hi, I just got "done" upgrading my project from 3.5 to 4.1, and it all works just peachy.  I have some RSL libraries that I reference in my main app and also a module app.  The modules and main app are both built in the 4.1 SDK.

       

      I took a look into the 4.5 SDK, and decided I wanted some of the new functionality.  So I switched all the projects to use 4.5.1 and now the modules will not create.  The module info loads up and looks correct, but calling moduleinfo.factory.create() now returns "null" into the module object.  What could be different from 4.1 to 4.5.1 that could cause this?  I'm rather distressed. 

       

      note:  I can leave the libraries in 4.5.1 and it works fine, but if either the module app or the main app are in 4.5.1 it fails.  The loading is done through a "manager" in one of the libraries.

        • 1. Re: upgrading from 3.5 to 4.5 - module load problem
          mitz11 Level 1

          also, modules are using halo components, if that matters.

          • 2. Re: upgrading from 3.5 to 4.5 - module load problem
            mitz11 Level 1

            I'm still stumped.  I re-downloaded the sdk and messed around with the compiler settings for my different apps. 

            I noticed that SOME of the modules will actually load up, but only a few.  I haven't been able to figure out what the common link is among those that are able to load. 

            • 3. Re: upgrading from 3.5 to 4.5 - module load problem
              Flex harUI Adobe Employee

              All SWFs involved must be compiled with the same version of Flex.  No mixing is allowed.  Modules may fail to load if their classes are already linked into the main app, which is a common mistake.  Link-reports will help you find it.

              1 person found this helpful
              • 4. Re: upgrading from 3.5 to 4.5 - module load problem
                mitz11 Level 1

                Okay, everything is definitely compiled on the same version. 
                So, I have the same library linked into the main application (RSL), and also being used as an RSL for the modules in the module app.  You think that's the problem?  Why would it work differently from 4.1 to 4.5?

                • 5. Re: upgrading from 3.5 to 4.5 - module load problem
                  mitz11 Level 1

                  Oh, and I don't link in any of the modules from the module app into the main app directly.  They are strictly loaded using the following:

                   

                  [...]
                  moduleInfoHash[path] = ModuleManager.getModule(path);

                  var mi:IModuleInfo = moduleInfoHash[path];

                  mi.addEventListener(ModuleEvent.READY, createFlashModule);

                  mi.load(null,null,null,FlexGlobals.topLevelApplication.moduleFactory);

                  [...]

                   

                  private static function createFlashModule(event:ModuleEvent = null):void

                  {

                       var mi:IModuleInfo = moduleInfoHash[path];

                       mi.removeEventListener(ModuleEvent.READY, createFlashModule);

                       mi.removeEventListener(ModuleEvent.ERROR, flashModuleErrorHandler);

                       var module:Object = mi.factory.create(); //Right here, the module normally loads up.  In 4.5.1, the module is null.

                  [...]

                  • 6. Re: upgrading from 3.5 to 4.5 - module load problem
                    Flex harUI Adobe Employee

                    What is moduleInfoHash?  If it is a weak key dictionary, you might be seeing things get garbage collected.  You need a strong reference to the IModuleInfo

                    • 7. Re: upgrading from 3.5 to 4.5 - module load problem
                      mitz11 Level 1

                      The moduleinfo hash is just an "object" type that I treat like a hash table that keeps track of all my module info.  I'm loading up lots of modules, sometimes multiple times, and don't want to re-load them more than once per run. 

                       

                      Anyway, that's not a problem, because I'm stepping through it in the debugger and the module info looks to be properly populated.

                      in the debugger, it looks a bit like

                       

                      mi = ModuleInfoProxy

                      -->  factoy = _DevSelector_mx_core_FlexModuleFactory

                      --> data = null

                      --> loaded = true

                      --> ready = true

                      etc.

                       

                      This looks right to me, anyway.

                      • 8. Re: upgrading from 3.5 to 4.5 - module load problem
                        mitz11 Level 1

                        I converted all of my modules over to sparks modules, and it does the exact same thing.

                        • 9. Re: upgrading from 3.5 to 4.5 - module load problem
                          mitz11 Level 1

                          Am I getting messed up by using flash builder 4.0 or something?  I got frustrated trying to figure out what went wrong with the big application I'm trying to port, and decided to try to reproduce the problem in a simple way.

                          I just made the simplest version of a moduler loader (via actionscript rather than MXML) that I could muster using two seperate applications.  One is a simple app that I run and it just looks like this:

                           

                          <?xml version="1.0" encoding="utf-8"?>

                          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                           xmlns:s="library://ns.adobe.com/flex/spark"

                                                           xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="onComplete()" minWidth="955" minHeight="600">

                                    <fx:Declarations>

                                              <!-- Place non-visual elements (e.g., services, value objects) here -->

                                    </fx:Declarations>

                           

                                    <fx:Script>

                                              <![CDATA[

                                                        import mx.events.ModuleEvent;

                                                        import mx.modules.IModuleInfo;

                                                        import mx.modules.ModuleManager;

                           

                           

                           

                                                        private function onComplete():void

                                                        {

                                                                  var mi:IModuleInfo = ModuleManager.getModule("../../test2/bin-debug/moduleThing4.swf");

                                                                  mi.addEventListener(ModuleEvent.READY, onReady);

                                                                  mi.addEventListener(ModuleEvent.UNLOAD, listener);

                                                                  mi.addEventListener(ModuleEvent.PROGRESS, listener);

                                                                  mi.addEventListener(ModuleEvent.SETUP, listener);

                                                                  mi.addEventListener(ModuleEvent.ERROR, listener);

                                                                  mi.load(null,null,null,this.moduleFactory);

                                                        }

                           

                                                        private static function listener(e:ModuleEvent):void

                                                        {

                                                                  trace ("stuff happened: " + e.toString());

                                                        }

                           

                                                        private function onReady(e:ModuleEvent):void

                                                        {

                                                                  var module:Object = e.module.factory.create();

                                                        }

                                              ]]>

                                    </fx:Script>

                          </s:Application>

                           

                           

                          The other is a module application that simply builds the following module:

                           

                          <?xml version="1.0" encoding="utf-8"?>

                          <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                 xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300">

                                    <fx:Declarations>

                                              <!-- Place non-visual elements (e.g., services, value objects) here -->

                                    </fx:Declarations>

                                    <mx:Button width="100" height="100" label="asdf"/>

                          </mx:Module>

                           

                          If I have both applications in 4.5.1, I get the error "VerifyError: Error #1014: Class mx.modules::Module could not be found."
                          If I have both applications in 4.1, I get no events after this mi.load call.  It just does nothing.

                           

                          I'm so completely confused by all of this.  This isn't even the SAME problem my other, large application was having. 

                          • 10. Re: upgrading from 3.5 to 4.5 - module load problem
                            mitz11 Level 1

                            One more thing worth mentioning, in 4.1, I get this message in my trace:
                            [SWF] C:\Users\MitzBits2\Adobe Flash Builder 4\test2\bin-debug\moduleThing4.swf - 139,011 bytes after decompression

                             

                            And yet it still does not fire any of the events that I am listening for.

                            • 11. Re: upgrading from 3.5 to 4.5 - module load problem
                              Flex harUI Adobe Employee

                              In this test case app, mi is in a local variable and it and the module can get garbage collected.

                               

                              There is already a cache in ModuleManager.  A request to the same URL does not cause reloading of the SWF if it is still in memory.

                               

                              -Alex

                              • 12. Re: upgrading from 3.5 to 4.5 - module load problem
                                mitz11 Level 1

                                Oh, good catch.  I fixed that, and now the test app loads up modules just fine.  There must be something very strange going on in my other program.  I guess there isn't much you can do to help me with that. 

                                 

                                In my program, I have a rather complicated module loading class, and the complexity largely comes from a workaround of a problem in flash 3.5.  The problem was that I couldn't load more than a couple modules in parallel without the download process freezing up on me.  Anyone have any idea if that's been fixed since then?  If so, I could get rid of all the complex module loading queues and replace them with something more normal and asynchronous.

                                • 13. Re: upgrading from 3.5 to 4.5 - module load problem
                                  mitz11 Level 1

                                  Okay, this has gone from a little strange, to completely baffling.  Since a handful of my modules WERE able to load up, and I discovered a brand new, blank module loaded fine, I decided to take one of my modules and slowly pick it apart until I found the exact thing making it fail.  In the particular module I chose, this is the line:

                                   

                                  private function getScreenResult(event:ResultEvent):void

                                  {

                                  }

                                   

                                  The contents of the function do not matter.  I commented them out.  All that matters is THAT line.  If it is present, when my module loading class does mi.factory.create();, it returns null.  If I comment that line out, it creates the module. 

                                   

                                  W-H-A-T is going on?  If you guys aren't tired of my wall of text, please help.  It's very appreciated.

                                  • 14. Re: upgrading from 3.5 to 4.5 - module load problem
                                    Flex harUI Adobe Employee

                                    Again, please verify you have hard, persistent, references to the IModuleInfo, otherwise you are seeing the randomness of the garbage collection.

                                    • 15. Re: upgrading from 3.5 to 4.5 - module load problem
                                      mitz11 Level 1

                                      I do.  The moduleinfo is not getting garbage collected, I am tracking it in a private static variable within my module loading class.  That reference is always there.

                                       

                                      I recreated the problem using a bare-minimum pair of applications, one for compiling the modules, and another for loading them.

                                      Here is the code for the loading application:

                                       

                                      <fx:Script>

                                                          <![CDATA[

                                                                    import mx.core.IVisualElement;

                                                                    import mx.events.ModuleEvent;

                                                                    import mx.modules.IModuleInfo;

                                                                    import mx.modules.ModuleManager;

                                                                    private var mi:IModuleInfo;

                                       

                                                                    private function onComplete():void

                                                                    {

                                                                              mi = ModuleManager.getModule("../../test2/bin-debug/moduleThing2.swf");

                                                                              mi.addEventListener(ModuleEvent.READY, onReady);

                                                                              mi.load(null,null,null,this.moduleFactory);

                                                                    }

                                       

                                                                    private function onReady(e:ModuleEvent):void

                                                                    {

                                                                              var module:IVisualElement = e.module.factory.create() as IVisualElement;

                                                                              this.addElement(module);

                                                                    }

                                                          ]]>

                                                </fx:Script>

                                       

                                      I made four modules - moduleThing1 through moduleThing4.

                                      moduleThing1:  an mx module with an mx button.  Fails to load, Error #1014: Class mx.modules::Module could not be found.

                                      moduleThing2:  an mx module with a sparks button.  Fails to load, Error #1014: Class mx.modules::Module could not be found.

                                      moduleThing3:  a sparks module with an mx button.  Fails to load silently.  e.module.factory.create() returns null.

                                      moduleThing4:  a sparks module with a sparks button.  Successful load.

                                       

                                      If I put these lines in the main application:

                                       

                                                                    import mx.modules.Module;

                                                                    private var test:Module;

                                       

                                      Then all modules load fine.

                                       

                                      It seems obvious to me now that the modules aren't able to get what they need for the mx components.  I'm not sure what's going on in my big application, since the modules are mx modules, and some of them fail and some do not, based on their contents, and they always fail silently (never with the error 1014).

                                       

                                      Everything is fixed if I choose "merge into code" for the framework linkage on the modules, but that's not a solution.

                                       

                                      There HAS to be a simple solution.  Any ideas?

                                      • 16. Re: upgrading from 3.5 to 4.5 - module load problem
                                        Flex harUI Adobe Employee

                                        I tried a similar test case and everything is working fine.  Your symptoms imply a configuration issue.  Make sure the SWCs used in the project are all built with 4.5 and that there aren’t old SWCs still in the library-path or source-path pointing to an older SDK.

                                         

                                        -Alex

                                        • 17. Re: upgrading from 3.5 to 4.5 - module load problem
                                          mitz11 Level 1

                                          Just to be sure, I deleted the 4.1 sdk and all files in bin-debug, then clean built both projects.  Still having the same problem.

                                          Can I not use flash builder 4.0?  Is that possibly the source of my woes?

                                           

                                          I guess I'm just sunk on this one.  I was really hoping I could use the 4.5.1 sdk for this application.

                                           

                                          Thanks for the help anyway, Alex!

                                          • 18. Re: upgrading from 3.5 to 4.5 - module load problem
                                            Flex harUI Adobe Employee

                                            Flash Builder 4.0 is not guaranteed to work with 4.5 SDK.

                                             

                                            Did you verify in your project properties that everything involved is on 4.5?  Of course, the issue might be that 4.0 doesn’t set all the config options for 4.5

                                            • 19. Re: upgrading from 3.5 to 4.5 - module load problem
                                              mitz11 Level 1

                                              I downloaded and installed FB 4.5 today, and the little test-applications work fine now.  I guess flash builder 4 didn't set the configuration right.  My main application has all kinds of new problems, though.

                                               

                                              One thing I've noticed is that it's making copies of the framework and my custom libraries EVERYWHERE.  Every folder I have modules in has copies of these things.  My module app never runs - I just use it to compile the modules, then load them up from the main app.  I feel like I should only need these things in a single folder, in my main app, and the modules should be able to reference those at runtime.  If I remove any of those files from their respective spots, I get something like "textLayout_1.1.0.604.swf failed to load. Error #2032: Stream Error.", which seems to indicate it's looking for those libraries in the EXACT folder.  Maybe I need to load these modules into the application domain now?  How do I do that?

                                               

                                              I read through http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf674ba-7fff.html, but I guess I didn't understand it very well.

                                              • 20. Re: upgrading from 3.5 to 4.5 - module load problem
                                                mitz11 Level 1

                                                I changed my custom libraries to be external, and that took care of them, but the framework classes are still all over the place.

                                                • 21. Re: upgrading from 3.5 to 4.5 - module load problem
                                                  Flex harUI Adobe Employee

                                                  4.5 and 4.0 default to using RSLs so all of the RSLs get copied to the output folder.  If things aren’t running something might be marked external that shouldn’t be, but rsls should be external for modules (but as rsls for the main app).

                                                  • 22. Re: upgrading from 3.5 to 4.5 - module load problem
                                                    mitz11 Level 1

                                                    Well, the last two problems I'm having are not game breakers.  Everything is working and loading up fine.  The problems are:

                                                    1.)  The main application doesn't load up a library called "rpc_4.5.1.21328.swf".  Some of my modules need this, apparently.  I'd like to force the main application to load that file up before the modules get loaded, so that it won't have to be sent over the network. Is there a way to do this?

                                                     

                                                    2.)  My modules application has the modules divided into several folders.  It is copying rpc_4.5.1.21328.swf, framework_4.5.1.21328.swf, spark_4.5.1.21328.swf, and textLayout_2.0.0.232.swf into EVERY ONE of those folders (there are quite a few).  These are completely unneeded. I can delete them and everything works fine (except for the rpc one which has to be present, but I'd like to fix that by loading it into the main application).  So, is there a way to keep it from dropping all these unnessecary files all over the place?

                                                    • 23. Re: upgrading from 3.5 to 4.5 - module load problem
                                                      Flex harUI Adobe Employee

                                                      In 4.5, the main app isn’t supposed to load up the rpc rsl.  The first module that needs it should cause the main app to load it.  I’m not sure why you have different output folders for each of the modules, but that is probably why each one gets a copy.  I suppose you could try to optimize that away by changing all libraries used by the modules to external and then get the main app to load the rpc rsl.  I thnk we added a compiler option to force-load the RSLs or you can simply create a dependency in the main app on a class in that RSL.

                                                      1 person found this helpful
                                                      • 24. Re: upgrading from 3.5 to 4.5 - module load problem
                                                        mitz11 Level 1

                                                        "The first module that needs it should cause the main app to load it. " - yeah, that's happening.  I just want to minimize what's served up over the connection to my module server.  I'll just create a dependency within the main app. 

                                                         

                                                        "I’m not sure why you have different output folders for each of the modules" - different folders for groups/categories of modules, not individual ones.  It's just for organization.  I guess when the code goes to production, I'll just remove the extra files that don't need to be in there, no big deal.

                                                         

                                                        Thank you for all your help.  Upgrading from 3.5 was really hard, but I think it's going to be worth it now that I can use all the new neat stuff!  I think my issues are solved.