Announcement Announcement Module
Collapse
No announcement yet.
Modules and Class not found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Modules and Class not found

    Hi All...
    I am digging into Spring ActionScript now but running into troubles w/ my application. I have split my app up using Flex Modules but when I try to get an object I get a "class not found error" from the ClassUtils.forName() ln 87 which is this line:

    applicationDomain.getDefinition(name) as Class;

    My app is set up as follows:

    1. Main app that contains login is a swf. It loads up Module A.
    2. Module A then loads Module(s) B-Z depending on which navigation the user selects.

    Currently I have the applicationContext.xml loading and parsing in Module B to configure the View and Services.

    I read some threads on loading and such, I was thinking that if the module loads that all the classes there in would be loaded in the ApplicationDomain. Am I seeing a no class found error b/c the class truly is not found? Maybe since it is a module, it is getting filtered out by the link report?

    Thoughts? TIA.

    -Al

  • #2
    just checking the obvious first...

    Just to be on the safe side here, sorry if I'm asking for the obvious:

    Are you sure that the classes you reference have been compiled into your modules? If the class is only referenced in your application-context the class won't be compiled into your module. You'd have to declare a dummy variable for each type you specify in your application-context, that way you force the compiler to actually include the class in the resulting swf.
    If that is the case, then double check that your modules are loaded in the same application and security domain, if all of that checks out it should work.

    cheers,

    Roland

    Comment


    • #3
      Hi Al,

      this is probably related to one of the following:
      - the name of the class is misspelled
      - the class is not compiled into the swf
      - the swf is not loaded into the main application domain

      regards,
      Christophe

      Comment


      • #4
        Thanks for the quick replies, just getting back to this after some holiday time. It was a case of security domain and misspelled package name.

        Thank you!
        -al

        Comment


        • #5
          ApplicationDomain how to solve?

          Hi i'm running into the exact same problem.

          No misspellings here. It definitely has to do with the ApplicationDomain.

          It gets really weird... I have a empty base app and module:
          ModuleAWrapper.mxml
          ModuleA.mxml

          ModuleA has a context and uses springactionscript.

          the module is loaded in a <mx:ModuleLoader url="ModuleA.swf" />

          works like a charm.

          But now the weird thing:
          If i load the module in a different application Main.mxml
          in the exact same way i get :

          Error: A class with the name 'nl.artim.projectx.module_a.command.HelloWorld2Com mand' could not be found. at as3reflect::ClassUtils$/forName()[C:\Users\Christophe\workspace\as3reflect\src\as3re flect\ClassUtils.as:89]...

          Main.mxml has it's own context but the class HelloWorld2Command only exists in ModuleA

          weird shit... But even stranger if i run the ModuleA in the empty wrapper
          and do the next statements inside ModuleA:
          ClassUtils.forName('nl.artim.projectx.module_a.com mand.HelloWorld2Command', ApplicationDomain.currentDomain));
          or
          ClassUtils.forName('nl.artim.projectx.module_a.com mand.HelloWorld2Command'));

          both give me a object.

          Now next test:
          if i load the module in the other application Main i get an object for:
          ClassUtils.forName('nl.artim.projectx.module_a.com mand.HelloWorld2Command', ApplicationDomain.currentDomain));

          and a runtime error for
          ClassUtils.forName('nl.artim.projectx.module_a.com mand.HelloWorld2Command'));

          So it has to do with application domains i guess. But in Main and the empty wrapper i didn't do anything with ApplicationDomains.

          Now because both the Module and Main are using springsource they both
          have asReflect. I looked in the source of the ClassUtils.forName
          and if it is not given an applicationDomain it assumes the currentDomain.
          Fair enough.

          If i pass in the the currentDomain from the the module i get a result,
          But if i run it without that parameter it looks like it's using the currentDomain from Main by passing the module which actually called the method! Weird scoping if you ask me...


          NB. The only other difference is that Main resides in another project and ModuleAWrapper and ModuleA are in the same project.

          I do publish all 3 items to the same directory. So it's not that im loading stuff from a different address.

          I tried setting the ApplicationDomain in the moduleLoader like:

          <mx:ModuleLoader url="ModuleA.swf" width="100%" height="100%" applicationDomain="{new ApplicationDomain(null)}" />

          and

          <mx:ModuleLoader url="ModuleA.swf" width="100%" height="100%" applicationDomain="{ApplicationDomain.currentDomai n}" />

          no luck....


          Any Ideas? This is so weird and causes me a headache...

          BTW Thanks for the ecxelent work on the framework. I love it!

          Thanx Arnoud

          Comment


          • #6
            maybe...

            I think the module needs to be loaded in the same appdomain and the same security domain as well, try this:


            Code:
            <mx:ModuleLoader url="ModuleA.swf" width="100%" height="100%"
                  applicationDomain="{ApplicationDomain.currentDomain}"
                  securityDomain="{SecurityDomain.currentDomain}"/>
            hope that helps, let us know of your findings.

            cheers,

            Roland

            Comment


            • #7
              no luck

              Hi,

              thanx for the quick reply. Unfortunately moduleloader doesn't have a property securityDomain...

              According to the doc's a module is always loaded in the same securityDomain


              BTW. I included the ClassUtils in the empty wrapper for module a,
              and now this one crashes too. At least i have predictable behaviour now


              so the conclusion for now is:
              - by default modules get loaded in a separate applicationDomain
              - if then a class is in both in the module and in the main app. The class in the main app is taken by default.
              - if that method references ApplicationDomain.currentDomain in it's body it takes the applicationDomain from main scope. EVEN IF ITS CALLED FROM THE MODULE!


              Any suggestions how to fix this?

              <mx:ModuleLoader id="ml" url="ModuleA.swf" width="100%" height="100%" applicationDomain="{ApplicationDomain.currentDomai n}" />

              should do the trick but it doesnt.... The module still gets a separate ApplicationDomain



              any module guru's around here

              Arnoud

              Comment


              • #8
                roll your own perhaps?

                I usually load modules with the ModuleManager, a little like this:

                Code:
                var info:IModuleInfo = ModuleManager.getModule(url);
                info.addEventListener(ModuleEvent.READY,handleReady,false,0,true);
                info.addEventListener(ModuleEvent.ERROR,handleError,false,0,true);
                info.addEventListener(ModuleEvent.PROGRESS,handleProgress,false,0,true);
                info.addEventListener(ModuleEvent.SETUP,handleSetup,false,0,true);
                info.load(ApplicationDomain.currentDomain,SecurityDomain.currentDomain);
                the info variable should be a globally declared one, otherwise the event handlers won't get called since it'll be garabge collected, watch out for that one.

                hope this helps a bit more...

                cheers,

                Roland

                Comment


                • #9
                  solved, nasty....

                  Hi Roland thanx again!

                  I dont think you need the security settings if you load from the same domain.

                  Anyway i found it and it's a bug in ModuleLoader....
                  I'll post my findings here cause someone else may run into this and its really nasty.

                  Ok here we go: this doesnt work:
                  <mx:ModuleLoader id="moduleLoader" width="100%" height="100%"
                  applicationDomain="{ApplicationDomain.currentDomai n}"
                  url="ModuleA.swf"/>

                  but this does!

                  <mx:ModuleLoader id="moduleLoader" width="100%" height="100%"/>

                  function onCreationComplete():void
                  {
                  moduleLoader.applicationDomain = ApplicationDomain.currentDomain;
                  moduleLoader.url = "ModuleA.swf";
                  }

                  apparently the set url is invoked first in the ModuleLoader class and this one
                  starts the load immediately. After that the applicationDomain is set. duhhhh!

                  Anyway thanx for the help Roland! I'll give the ModuleManager a shot too while im at it. Lokes as a clean approach too.

                  Arnoud

                  Comment


                  • #10
                    that IS nasty!

                    Hey Arnoud,

                    ouch man, that one is indeed a filthy... Better file a report for this one in the Flex SDK JIRA as well, that could save other people a bit of pain in the future perhaps.

                    Thanks for sharing your findings!

                    greets,

                    Roland

                    Comment


                    • #11
                      done!

                      http://bugs.adobe.com/jira/browse/SDK-21055

                      cheers!

                      Comment


                      • #12
                        done too!

                        Voted

                        nice job!

                        Comment

                        Working...
                        X