LazyStack gethub Example and multiple contexts

visnik's Avatar


29 Jul, 2011 05:39 PM

I have another question looking through the examples from the gethub repository. I am looking at the LazyStack example and it looks like it uses multiple contexts, and I am mostly looking for clarification. in the LazyStack.mxml it loads two instances of the MainView component here:

<lazystack:MainView label="Lazy!"/> <lazystack:MainView label="Lazy 2!"/>

It would seem each MainView component instantiates a context for each one here:

`private var context:MainViewContext;

        private function onPreInitialize():void
            context = new MainViewContext(this);


So for clarification, we are getting two separate context, with each having a displayObjectContainer as MainView1 and MainView2 respectively?

Are these both wired into the framework, so as an example if i were to dispatch an event from a command or model, any views mapped to its corresponding mediator within any context could hear it? or just within the scope of each particular context?


OH, and I also see a uid property in the, what is the purpose of this property?

  1. 1 Posted by visnik on 29 Jul, 2011 07:09 PM

    visnik's Avatar

    Ok, I think I found the answer my own question here looking at the best practices again. I found this

    ' Framework actors live within a context and communicate with one another within the scope of that context. It is possible to have several contexts within a single application. This is useful for applications that want to load external modules. While the actors within a context can only communicate within the scope of their context, it is possible for contexts to communicate with one another in a modular application."

  2. visnik closed this discussion on 29 Jul, 2011 07:09 PM.

  3. visnik re-opened this discussion on 29 Jul, 2011 08:14 PM

  4. 2 Posted by visnik on 29 Jul, 2011 08:24 PM

    visnik's Avatar

    OK, maybe i closed this a little premature, as I still have question regarding the multiple context, and scope. I decided to mess around with multiple context as a result of looking at the LazyStack example, and realized... I am going to have to have a model for each context. Here is what I am doing that lead me to that conclusion.

    I have my MainApp.mxml, it has has a MainScreenContainer.mxml component within it. I was thinking about dynamically loading some screens (that will have there own states) in and out of this MainScreenContainer.

    So in ScreenOne.mxml I have the following:

    `private var context:NewGameContext;

    private function onPreInitialization():void
        context = new ScreenOneContext(this);       

    and will pretty much do the same for all other screens.

    I got thinking, I will need a model for each screen, as each model will only be scoped for it's context.

    Am I incorrect in thinking this?

  5. 3 Posted by Michal Wroblews... on 30 Jul, 2011 11:29 AM

    Michal Wroblewski's Avatar

    Hi visnik,

    In the example you mentioned @Shaun shows that you can create multiple contexts of the same type in one application.

    I'm wondering if you're going to load external SWFs with their contexts or just to add views dynamically. If you're going to load external SWFs I'd rather recommend you modular contexts by @Joel Hooks - Here you can find a description of that utility. If your're just going to add views dynamically I think you don't need separate contexts for that, but it doesn't mean it won't work. If they'll need to comunicate between each other, and inject common objects, use one context for all the application or use Modular utility by @Joel.

    If it doesn't satisfy you, give me more details :)


  6. Support Staff 4 Posted by Shaun Smith on 30 Jul, 2011 01:20 PM

    Shaun Smith's Avatar

    Hi visnik,

    I hope that example wasn't too misleading - it is very old and not very clear. It's purpose was simply to demonstrate that multiple identical contexts can live side-by-side in an application without interfering with each other. It does not represent a typical use-case by any means.

    Most applications will have just a single context. In your case, I would have one context and separate mediators for each dynamically added screen.

    Hope that helps

  7. 5 Posted by visnik on 02 Aug, 2011 03:50 PM

    visnik's Avatar

    Thanks guys, I appreciate you help. @Michal I am currently diving into the Modular context by Joel Hooks, trying to learn as much about RL as I can. Thanks, your replies were very helpful.

  8. visnik closed this discussion on 02 Aug, 2011 03:50 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