'static' view in different other views

andreas's Avatar


03 Nov, 2011 12:54 PM


I am currently refactoring a bigger application to robotlegs.
I have a window (a spark group) with different tabs/menus (again extended spark groups inside a ViewStack in the window). Each menu has its own Mediator and some gui-components that are different, but there is one box (also a group) that is the same in every menu. This box also has a mediator to dispatch events that maybe update the currently opened menu.

How do I add the box to the window?
Now I have a static variable that saves the box an i just use removeElement(box)/addElement(box) every time the user changes the menu. Is it possible to have the view as a singlton and add it to the menu in the mediator or is there any other way to solve this?

  1. Support Staff 1 Posted by Ondina D.F. on 03 Nov, 2011 02:59 PM

    Ondina D.F.'s Avatar

    Hi Andreas,

    Let me ask a few questions, to make sure I understand what you mean:

    You have a view(Group), let’s call it ViewStackContainer and it holds a ViewStack with different SubViews.
    Currently you are adding the “Box” to each SubView in the stack, right?
    If so, I would place the “Box” in the ViewStackContainer instead of adding and removing it to/from each SubView.
    I also would have a ViewStackContainerMediator if I wanted to influence the ViewStack's navigation from else where in my app.

    Is the “Box” always performing the same actions, or does it change depending on the selected View in the stack?

    What do you think?


  2. 2 Posted by andreas on 03 Nov, 2011 03:18 PM

    andreas's Avatar

    Hi Ondina,

    Thank you very much for your answer.
    You are correct, the "Box" is in every SubView.
    In my box I have a DropDownList where the user can select an item and each subview should show the data for this item, so it is not possible to navigate through the ViewStackContainer with this "Box" and the action is depending on the selected View.

    I use a template engine to genrate some more "window"-mxml-files, so its not the easiest thing to just add something to the ViewStackContainer, because it is in a generated file but it is a good idea... so modifing my template file is a first solution, if you don't have any better Ideas I will do that.

  3. Support Staff 3 Posted by Ondina D.F. on 03 Nov, 2011 03:40 PM

    Ondina D.F.'s Avatar

    Andreas, you’re welcome:)

    I posted an example of a mobile app in another thread. Sure, it is different from a Flex ViewStack, but the idea is somehow the same: http://knowledge.robotlegs.org/discussions/problems/408-mobile-view...

    Could you take a look at it?

    1. The user selects an item from a List in SomeView, which is mediated (SomeMediator).
    2. SomeView dispatches an event with the list.selectedIndex.(or item or whatever you need) as a payload
    3. SomeMediator re-dispatches it .
    4. Now, this event could trigger a command or it could be listened to by another Mediator, namely the Mediator of the ViewStackContainer. So, the ViewStackContainerMediator would pass the event.payload (with the list.selectedIndex) to a method in
    5. ViewStackContainer, which then will change the ViewStack.selectedIndex to the one selected in the List and also the additional data you'd need

    I would place SomeView either in the ViewStackContainer or in the parent of the ViewStackContainer, anyway just once in one place.
    SomeView and ViewStackContainer communicate through their mediators via events.
    Would that work for you?
    I hope it wasn’t too confusing.

  4. Support Staff 4 Posted by Ondina D.F. on 03 Nov, 2011 03:58 PM

    Ondina D.F.'s Avatar

    Or if you don’t have to change the ViewStack.selectedIndex when the user selects an item from the List, and you just want to show some specific data for a subview, you can dispatch the data from SomeMediator (here just simplified, in reality you probably would need a Model and Command too), and every SubViewMediator would listen to it . In this case you’d have to let the SubViews mediators decide if the incoming data is the one they need.

    Or you can dispatch an event with different event types for each item in your list.
    Say, SomeDataEvent would have
    SomeDataEvent.DATA_FOR_VIEW_THREE as event types.
    And the SubViewOneMediator would listen for SomeDataEvent.DATA_FOR_VIEW_ONE
    , SubViewTwoMediator would listen for SomeDataEvent.DATA_FOR_VIEW_TWO and so on.


  5. 5 Posted by andreas on 03 Nov, 2011 04:01 PM

    andreas's Avatar


    That's exactly how my Mediator for the "Box" works, so its not confusing at all.
    My problem is, however having the same object in different views, which is not a good Idea, so I will put my "Box" in the parent (using a little template magic so that this only happens in the right window).

    Thank you again for your time and for your very fast response.


  6. andreas closed this discussion on 03 Nov, 2011 04:04 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