Multiple Contexts using the same Context View

alexander.david.r's Avatar


12 Sep, 2012 05:52 AM

Greetings All,

I have a bit of a pickle that I am trying to solve and I think I have narrowed my issue down to this. We have a RL modular application with two contexts in it, one for the main application and one for the swc library that we load in. Of course the context for the main application will use that as its context view but what we are trying to see about doing is having the libraries context use the parentApplication as its context view instead of just the component its started in. The reason for this is there are some mediators in the library that we have mapped there already that are tied to interfaces. These interfaces are implemented in components outside of the library and those components will be added to the stage in a different area that, unless the librarys context is set to the parentApplication, the library will now know about.

My question is: Is something like this possible? Is there a restriction in place to only allow one context class per context view? Or can a context have multiple views?

Any help or insight would be greatly appreciated.

  1. 1 Posted by neil on 12 Sep, 2012 08:11 AM

    neil's Avatar

    I don't know whether this will work or be a good idea in your case, but I have certainly used this technique before. Mainly when my modules do not have their own view, and rely on the application view as their display list.

    so my main context. view is the main mc and my module contexts view is also the main view.
    On top of this remember that any mappings in your main -shell context will be available in the modules unless overwritten.
    so you have many contexts sharing one view.

    is that what you meant?

  2. 2 Posted by alexander.david... on 13 Sep, 2012 12:04 AM

    alexander.david.r's Avatar

    Close. I do agree with the overriden mappings concept and its one of the features of RL that we take advantage of a lot. It has given us the ability to provide a base set of classes that are used by default that can be over written with the other applications mappings if they so desire for one reason or another. Its handy :)

    Now I have setup the contexts for both the parent app and the library to use the ModularContext as the base instead of just the regular context. This was in response to another question I had posted on the 10th which was working out well initially. We are also using the ViewInterfaceMediatorMap class that I was able to retrieve from github. The issue I have now is communication between the classes in RL. When I dispatch an event from the parent applications mediators (whether by dispatch or dispatchToModules) the registered listeners in the library do not seem to pick it up. Would it be due to a possible issue with the Modular classes? Or maybe some other need to register them?

  3. Support Staff 3 Posted by Ondina D.F. on 13 Sep, 2012 03:32 PM

    Ondina D.F.'s Avatar

    Hi David,

    Adding to Neil’s suggestions:

    Supposing you have something like this:
    a. Main application: ApplicationView, ApplicationMediator and an ApplicationContext
    b. Library Project: LibraryView, LibraryMediator and LibraryContext
    Let's say LibraryView will be added to ApplicationView, and the 2 Views want to communicate with each other via events(through their Mediators...)

    Use case 1:
    The contextView for the LibraryContext is LibraryView
    Use case 2:
    The contextView for the LibraryContext is ApplicationView

    Use case 1:

    In ApplicationContext you have to do this:


    and in LibraryView this:

    public function set parentInjector(value:IInjector):void
    context=new LibraryContext(this, value, this.loaderInfo.applicationDomain.parentDomain);

    Use case 2:

    In ApplicationContext:

    mediatorMap.mapView(LibraryView, LibraryMediator );

    In LibraryMediator :

    public var injector:IInjector;
    override public function onRegister():void

    In LibraryView:

    public function set parentInjector(value:IInjector):void
    context=new LibraryContext(this.parentApplication.parent, value, this.loaderInfo.applicationDomain.parentDomain);               

    Of course the 2 Mediators have to extend ModuleMediator, as the 2 contexts have to extend ModuleContext.
    Now ApplicationMediator and LibraryMediator can communicate with each other.

    Anyway, if you register LibraryContext with the ApplicationView as a contextView, you have to find a way to pass the parentInjector into your library’s context.

    Maybe the idea of extending a BaseContext from a library wasn’t that bad. Take a look at the following example, even if it’s not exactly what you want to achieve:
    Jonathan Campos’ Code for his book Flex Mobile In Action:

    Library Project: RottenTomatoesBaseContext

    Mobile App: RottenTomatoesContext

    If none of the above suggestions help you solve your problem, could you post some code (mappings, creation of the contexts, etc) or attach a simplified app ?
    [EDIT] LibraryContextView => LibraryView and LibraryContextMediator=>LibraryMediator (hmm, lots of typos..)


  4. Support Staff 4 Posted by Ondina D.F. on 14 Sep, 2012 08:22 AM

    Ondina D.F.'s Avatar

    Other things to consider:

    • order of the mappings: Is the component/module that needs mappings added to the stage before the mappings occur?
    • “Keep a Reference to Your Context or it will be Garbage Collected”

    When I dispatch an event from the parent applications mediators (whether by dispatch or dispatchToModules) the registered listeners in the library do not seem to pick it up

    When you say „registered listeners“ are you referring to Mediators?
    If so, is their onRegister() running, can you trace it?

    If you’re triggering Commands instead, how and where have you mapped the events to the commands?

  5. Ondina D.F. closed this discussion on 20 Sep, 2012 02:49 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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