Is there a way to use two the same views (with mediator) at the same time?

edeventner's Avatar

edeventner

20 Oct, 2011 02:50 AM

Hello,

The first view will load up another view of itself in a window. Launching up a window through a command works just fine but when I uncomment my view component (which is just the first view) inside the window, it throws an error

 TypeError: Error #1009: Cannot access a property or method of a null object reference.

and when I tried to add the following lines on the command (LaunchWindowCmd) that will launch the window:

 [Inject] public var window:Window;
 [Inject] public var view:View; // added line

 exucute()
  window.open();
  mediatorMap.createMediator(window);
  mediatorMap.createMediator(view); // added line

produces the following error:

 Error: Injector is missing a rule to handle injection into target [object LaunchWindowCmd]. Target dependency: views::View

Here's the sequence:

 View loads
      -- some logic is done in the model and when true, launches a window of itself
      launch Window
          -- contains the View component

Is this possible in RL?

  1. Support Staff 1 Posted by Ondina D.F. on 26 Oct, 2011 03:57 PM

    Ondina D.F.'s Avatar

    Hello,

    I have read your question a couple of times, but I’m still not sure that I understood it :)
    I don’t know if this will help you, but let me try a very simple scenario:

    In a Model you’re dispatching an event that triggers a Command, yes?
    So in your Model you do this:
    dispatch(new SomeOpenWindowEvent(SomeOpenWindowEvent.OPEN_WINDOW));
    where SomeOpenWindowEvent is mapped to SomeOpenWindowCommand as you’ll see in the following example:

    SomeWindow.mxml

    <s:Window ....>

    <s:Label id="someWindowLabel" x="22" y="20" text="Label"/>
    

    </s:Window>

    SomeView.mxml

    <s:Group ....>

    <s:Label id="someViewLabel"  x="185" y="127" text="Label"/>
    

    </s:Group>

    In your Context class or where you do the mappings:
    mediatorMap.mapView(SomeView, SomeViewMediator, null, false); //don't autocreate
    mediatorMap.mapView(SomeWindow, SomeWindowMediator, null, false); //don't autocreate
    commandMap.mapEvent(SomeOpenWindowEvent.OPEN_WINDOW, SomeOpenWindowCommand, SomeOpenWindowEvent);

    In SomeOpenWindowCommand.as:

    
    import yourpath.views.components.SomeView;
    import yourpath.views.components.SomeWindow;    
    [Inject]
    public var event: SomeOpenWindowEvent;
    private var someWindow:SomeWindow;
    private var someView:SomeView;
    
    override public function execute():void
    {
    someWindow=new SomeWindow();
    someWindow.open();
    someWindow.title=event.payload;
    mediatorMap.createMediator(someWindow);
    someView=new SomeView();
    someWindow.addElement(someView);
    mediatorMap.createMediator(someView);
    }
    

    In SomeWindowMediator.as

    
    import yourpath.views.components.SomeWindow;
    import org.robotlegs.mvcs.Mediator;
    
    public class SomeWindowMediator extends Mediator
    {
    [Inject]
    public var view:SomeWindow;
    
    override public function onRegister():void
    {
    view.someWindowLabel.text="SomeWindowMediator onRegister";
    }       
    }
    

    In SomeViewMediator.as

    
    import yourpath.views.components.SomeView;
    import org.robotlegs.mvcs.Mediator;
    
    public class SomeViewMediator extends Mediator
    {
    [Inject]
    public var view:SomeView;
    
    override public function onRegister():void
    {
    view.someViewLabel.text="SomeViewMediator onRegister";
    }       
    }
    

    You could add SomeView to SomeWindow in the SomeWindowMediator’s onRegister() as well:
    someView=new SomeView();
    view.addElement(someView);
    mediatorMap.createMediator(someView);

    There are other ways to do the same, but maybe the example above will give you some ideas.
    Tell if it helps or not:)

    Ondina

  2. Support Staff 2 Posted by Ondina D.F. on 02 Nov, 2011 05:18 PM

    Ondina D.F.'s Avatar

    Closing discussion.
    Feel free to reopen this discussion in case you have more questions or you need further assistance with this issue. Please open new threads for new issues.
    Ondina

  3. Ondina D.F. closed this discussion on 02 Nov, 2011 05:18 PM.

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