Trying To Load Modular SWF's into a Modular Shell
Hey guys, I am working with your Modular Utility to load and unload modular swfs into the main application shell. I have been obsessively researching this trying to find fixes for my errors I am getting. I've found a few relevant posts on this topic (namely: http://knowledge.robotlegs.org/discussions/problems/160-child-appli... )
I am still having trouble successfully loading in the modular swf without getting that same error about the ApplicationDomain.getDefinition().
What I am doing is mapping the module in the shells context as type "IModule" so that I do not import all of the classes contained within the module into the shell. I then added the "set parentInjector" method in the module's doc class and also make that module document class implement IModule. so in the shell, I load in the module and manually set the injector using the above method. Conceptually it seems like this should do the trick, but i keep running into that same old application domain error. I've tried all sorts of things to fix this with absolutely no success.
Things I've tried / am currently experimenting with:
-Loading the module into its own application domain
-Setting the application domain on the injector ( i.e SwiftSuspendersInjector(injector).setApplicationDomain(contextView.loaderInfo.applicationDomain); )
-Running createChild() on the injector after it is passed to the module.
-Setting the AppDomain on the injector after it is passed to the module (i.e. value.applicationDomain = this.loaderInfo.applicationDomain;)
So far I've had no success with the above. Also, something to note is that I am passing the injector to the module by first injecting it into the shells view mediator (i.e. [Inject] public var injector:IInjector;), then when adding the module to the view component, i also pass in the "injector" and set it after the module is added.
Any Idea about what I could possible be doing wrong?
I am now using the latest release of the RL package (1.4) with this modular util.
Thanks in advance!
Justin
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Justin on 10 Jan, 2011 04:57 PM
UPDATE*
I noticed that upon adding the module to my view component after loading the swf in the shell, it seems to be somehow automatically running the "set parentInjector()" method. So I removed the logic where I manually set this... still no success though.
Support Staff 2 Posted by Till Schneidere... on 10 Jan, 2011 05:49 PM
Hi Justin,
are you maybe setting the loading SWF's contextView in the loaded
SWF's module context's injector? That would be the only explanation I
can come up with right now.
Incidentally, I started writing some unit tests for SwiftSuspenders'
handling of applicationDomains in child injectors over the weekend
(and I can safely say that applicationDomains *don't* want to be unit
tested - at all!), so I would be very interested in reduced test-cases
of reproducible problems in this area.
If you can come up with such a reduced test-case, I'd gladly take a
look at the problem and fix related bugs in SwiftSuspenders, should
any turn up.
cheers,
till
3 Posted by Justin on 10 Jan, 2011 07:23 PM
Thanks for the quick response!
I'm not really following the first part, you asked:
"are you maybe setting the loading SWF's contextView in the loaded SWF's module context's injector? That would be the only explanation I
can come up with right now."
I'm basically just loading in the module into the shell without using a LoaderContext at the moment. In the shell context i'm mapping the viewType as "IModule". When I load the module and right when I add it to the stage it automatically calls the "set parentInjector()" method that is being "Injected" into the modules doc class, here i traced the value of the injector when it is passed into the module to make sure it is not null, here's the trace: "[object SwiftSuspendersInjector]" -it seems to be successfully passing the injector. But for some reason, in the "set parentInjector()", method injected into the modules doc class, when I add in the code to create the context and I pass the context: "(this, injector)", I get the ApplicationDomain.getDefinition() error.
Thanks again!
Justin
Maybe I have to manually set something in the shell or in the modules context.
4 Posted by Justin on 10 Jan, 2011 07:29 PM
Oh the first part of the error I am receiving is this:
"Exception fault: ReferenceError: Error #1065: Variable ModuleLandscape is not defined."
... where "ModuleLandscape" is the module swf that I am loading in. So it seems as if it expects me to map the exact module type in the shells context, but I already mapped the type of "IModule".
5 Posted by Martin on 11 Jan, 2011 10:19 AM
Hi Guys,
I think I've got the same problem here. I'm loading modules dynamically in shell with ModuleManager and when I'm trying to use child domain I'm getting a similar error.
When I use current domain all is working but references like: _ModuleName_mx_core_FlexModuleFactory prevent modules from being able to fully unload. Using a child domain should fix this.
I modify an example I found somewhere to demonstrate this error.
Thanks
Support Staff 6 Posted by Till Schneidere... on 11 Jan, 2011 11:16 AM
Hey Martin,
looking forward to your example. As I said, I'd really like to debug
and fix this.
cheers,
till
7 Posted by Martin on 11 Jan, 2011 01:50 PM
Hey Till,
Fxp attached to last post. Thanks!
Would be great if Justin can look at it and let us know if that's exactly same problem.
Support Staff 8 Posted by Till Schneidere... on 11 Jan, 2011 02:21 PM
Thanks Martin, I didn't see the attachment. Will take a look and see
what I come up with.
9 Posted by Justin on 12 Jan, 2011 03:29 PM
Hey Martin, I just downloaded that attachment and fired it up in flash builder and it appears to be the exact same issue I am having when trying to load a modular swf:
"ReferenceError: Error #1065: Variable M2 is not defined."
I am really curious to what this could be and how to fix it.
Thanks for posting your example! Hopefully we can find a remedy.
-Justin
Support Staff 10 Posted by Till Schneidere... on 12 Jan, 2011 06:39 PM
I took some time to debug this today and found the reason and a
workaround for the described problem.
When instantiating loaded modules, Flex does some stuff that leads to
the module's loaderInfo not containing the module Loader's
ApplicationDomain. Instead, it contains the main application's
ApplicationDomain.
To work around this, you can change your module's context's
constructor in one of two ways:
1. If you're certain that your module will always be implemented as a
Flex module, you can use this:
super(contextView, true, injector,
contextView["moduleFactory"].info().currentDomain);
2. If, on the other hand, you want your context to be agnostic of the
module's exact implementation, you can use this:
var applicationDomain : ApplicationDomain =
(contextView["moduleFactory"] && contextView["moduleFactory"].info) ?
contextView["moduleFactory"].info().currentDomain :
contextView.loaderInfo.applicationDomain;
super(contextView, true, injector, applicationDomain);
The second solution performs a dynamic check for the existence of
information that Flex modules keep, while the first solution just
assumes the information exists.
11 Posted by Justin on 12 Jan, 2011 07:19 PM
Hey Till, this looks great! Thanks for spending the time to do this.
I am building a pure as3 project compiling with the FLex SDK but i am not using the flex framework, so would you recommend that I use the second "agnostic" approach?
I've tried it out and am getting an error when using the second approach:
"Error #1069: Property moduleFactory not found on ..."
I am very confused about what "moduleFactory" is. Am I supposed to swap that out with the type of my module or something?
Thanks again!
Justin
Support Staff 12 Posted by Till Schneidere... on 12 Jan, 2011 07:33 PM
Hi Justin,
it sounds like your problem is actually unrelated to the one Martin's
example demonstrates.
I'm afraid I won't be able to help you without some kind of example
demonstrating *your* problem, then. If at all possible, having a
reduced test-case would be perfect, but if you can't manage to create
that, I would offer to have a look at your code instead. I'd guarantee
to keep it confidential of course if you send it to me in private
mail.
cheers,
till
13 Posted by Justin on 12 Jan, 2011 08:50 PM
Hey Till, I just whipped up a simple project in Flash Builder and am attaching the Flash Builder .zip project to this post.
All it is composed of is a Shell Module and a TestModule swf that I load into the shell. If you run the the main application, you would just need to click on the big red sprite to load in the module swf, and then it gets added to the main sprite (the Document class). This is when I get the error:
ReferenceError: Error #1065: Variable TestModuleView is not defined.
Again, thanks for your patience! I really appreciate all of your help.
-Justin
Support Staff 14 Posted by Till Schneidere... on 13 Jan, 2011 10:09 AM
Thanks for the test-case, I'll have a go at it later today.
And don't worry about my patience. I see it as a division of labor:
You provide feedback and a test-case, I get a head-start in debugging
I wouldn't have got had I stumbled upon the problem in one of my own
projects.
15 Posted by Justin on 13 Jan, 2011 03:40 PM
Right on Till! Sounds good to me. I'm sure this issue is not too terrible, I'm just surprised that this hasn't been an issue before... that is, loading external RL module swfs into a modular shell outside of the flex framework. Or at least not an issue that has been solved and documented from what I can tell. I'm looking forward to getting to the bottom of this one.
16 Posted by Martin on 14 Jan, 2011 12:30 PM
Hey Till!!!
Thanks for a fix. It's working great. Shame it's not a solution for Justin so extra thanks for double work. Must say that I'm working on my first Robotlegs project and I absolutely love it! Keep up great work!! Cheers
Support Staff 17 Posted by Till Schneidere... on 24 Jan, 2011 12:00 AM
Hi Justin,
I'm really sorry for not replying earlier. I finally had a look at
your example and it seems like there are some things wrong with it
outside of anything the Injector does:
First of all, your constructor call to TestModuleContext is wrong: The
second parameter should be of type "Boolean" and tells the context
whether it should automatically start up after the view has been added
to the Stage. Unfortunately, this error is a bit hard to spot because
the compiler only warns about the injector you're providing as the
second parameter being coerced to a boolean value instead of throwing
an error.
Just adding a "true" as the second parameter should fix this problem.
Unfortunately, I'm afraid I won't be able to be of much help with the
second problem as I don't really know that much about Flex's module
support: Flex modules can't be loaded with a normal Loader, you'll
have to use a ModuleLoader instead. It might be a simple case of
changing the Loader to a ModuleLoader and recompiling, but I'm not
sure about that.
I'd recommend taking a look at Martin's now working example, as it
seems like it would show how to properly load Flex modules into child
ApplicationDomains.
cheers,
till
Stray closed this discussion on 18 Feb, 2011 07:10 PM.