When you optimize a module, classes are removed from the module and must be found in the parent applicationdomain. For me, if I then load the module into an app that doesn't supply the missing classes, I see verify errors, but some folks seem to see nothing, just silent failure. So first, you have to make sure required classes exist in the module or in its parent applicationdomain.
Then, once you get it to load, further requests to load the same URL will just be ignored and the same factory is returned. That means all instances created by the factory will be from the same appdom and share singletons. To not share, you can try adding fake params to the url. That should generate a separate child appdom with its own singletons as long as those classes aren't inherited from the parent appdom. Alex Harui Flex SDK Developer Adobe Systems Inc.<http://www.adobe.com/> Blog: http://blogs.adobe.com/aharui From: [email protected] [mailto:[email protected]] On Behalf Of Everson Alves Sent: Tuesday, August 18, 2009 10:01 PM To: [email protected] Subject: Re: [flexcoders] Singletons and Modules - Application domain problem I did that too, in fact I explained it in the first mail, when I tried: moduleInfo.load(new ApplicationDomain(ApplicationDomain.currentDomain)) it dispatches a ModuleEvent.ERROR saying that file isn't a loadable module or something like that. Also i tried var somObj:SomeInterface = module.factory.create as SomeInterface var somObj:Object = module.factory.create; var somObj:*= module.factory.create; when loading using moduleInfo.load(); On Wed, Aug 19, 2009 at 1:19 AM, Alex Harui <[email protected]<mailto:[email protected]>> wrote: If you use "new ApplicationDomain()" then module.factory.create() will return an object of an unknown type because you've created a whole new applicationDomain with different classes so the type of what you create is not going to match. Your code probably does this: var somObj:SomeInterface = module.factory.create as SomeInterface So the "as" returns null. With modules you must use a child applicationdomain i.e. "new ApplicationDomain(applicationDomain.currentDomain)" so that the interface is shared. The next trick is to get the ModuleManager to attempt a second load in a separate child applicationdomain so fake url params might work. As long as the singletons are not in the main app, each child appdomain should have its own singleton. Alex Harui Flex SDK Developer Adobe Systems Inc.<http://www.adobe.com/> Blog: http://blogs.adobe.com/aharui From: [email protected]<mailto:[email protected]> [mailto:[email protected]<mailto:[email protected]>] On Behalf Of Everson Alves Sent: Tuesday, August 18, 2009 5:28 PM To: [email protected]<mailto:[email protected]> Subject: Re: [flexcoders] Singletons and Modules - Application domain problem The problem is that when I try to load it into a different applicationDomain other than ApplicationDomain.currentDomain , even the first instance won't load. ModuleEvent.READY is dispatched but moduleEvent.module.factory.create() gives me null. On Tue, Aug 18, 2009 at 8:45 PM, Alex Harui <[email protected]<mailto:[email protected]>> wrote: A module is a factory of potentially many instances, so multiple requests to load the same url are ignored and the same factory is returned to create the instance. You might try adding dummy url variables to see if you can fool ModuleManager into loading the module SWF again. Alex Harui Flex SDK Developer Adobe Systems Inc.<http://www.adobe.com/> Blog: http://blogs.adobe.com/aharui From: [email protected]<mailto:[email protected]> [mailto:[email protected]<mailto:[email protected]>] On Behalf Of Everson Alves Sent: Tuesday, August 18, 2009 4:38 PM To: [email protected]<mailto:[email protected]> Subject: Re: [flexcoders] Singletons and Modules - Application domain problem It's a good post but doesn't solve my problem without a lot of changes in the whole application. What i was really wanting from here is to know why I can't load the modules into different application domains. I'll use a ModelLocator factory per conversation instead of Singleton, but that requires changing in a lot of places, mainly propageting the conversationId all components and classes that need to access the modelLocator. On Tue, Aug 18, 2009 at 6:35 PM, Everson Alves <[email protected]<mailto:[email protected]>> wrote: I'll have a look at it say the outcome here. Thanks. On Tue, Aug 18, 2009 at 6:03 PM, Rick Winscot <[email protected]<mailto:[email protected]>> wrote: Take a look at a good write-up by Steve Brownlee... http://www.fusioncube.net/index.php/cairngorm-sharing-a-common-modellocator-with-modules With the added security restrictions... Your singleton implementation may need to be hardened to prevent multiple instance... Etc. This example may help as well. http://www.quilix.com/node/5 Cheers, Rick Winscot On 8/15/09 12:11 PM, "Everson Alves" <[email protected]<http://[email protected]>> wrote: Hello guys, I'm facing a weird problem. I'm working with flex Modules that are tide mxml components . Using ModuleManager to load the modules. If I load using moduleInfo.load(ApplicationDomain.currentDomain) it loads fine but as I want to use the module as independent sub applications and they use the same class definitions that doens't play nice with singletons (ModelLocator) . When loading using moduleInfo.load() expecting that it uses it's own ApplicationDomain it loads, dispatches ModuleEvent.READY event but moduleEvent.module.factory.create() gives me null. I also tried moduleInfo.load(new ApplicationDomain(ApplicationDomain.currentDomain)) but this case dispatches a ModuleEvent.ERROR saying that file isn't a loadable module or something like that. An detail that might be important is that the module is marked to be optimized to my application in compilation. thanks in advance. -- Jhonny Everson -- Jhonny Everson -- Jhonny Everson -- Jhonny Everson

