My main view does not result in mediator methods being called

rob's Avatar

rob

26 Aug, 2010 09:08 AM

Hi,

I am using Robotlegs for the first time, I think I have the concepts nailed down, but it would appear I can't get much working ;-)

First, I have a main view, that's an MXML file for Flex 4. I've added the declaration for the context and confirmed that the context is being initialised successfully.

Within the context I have an entry to map the view class to a mediator class.

The mediator does not get invoked, I have checked that it has an [Inject] annotation for the main view.

I feel that this is something to do with the MXML file existing prior to the context being initialised, is this correct?

I would post the code, but that's on a different machine that I don't have access to, but I'm hoping to learn something new here for the train journey home.

On a slightly different note, I have seen examples that refer to 'Sprite', when do I need to know / worry about that - is it an alternative to Flex?

Once I have this correct, I plan to either blog or create a screencast to help others - the ones I have followed jump around a lot, or are too basic to get to grips with.

Cheers,
Rob.

  1. Support Staff 1 Posted by Shaun Smith on 26 Aug, 2010 11:17 AM

    Shaun Smith's Avatar

    Hi Rob,

    1. Are you setting the contextView in your MXML context declaration? It should look something like this:

      <fx:Declarations>

      <ns:SomeContext contextView="{this}"/>

      </fx:Declarations>

    2. Does your context's startup() method run? Your context might look something like this:

    public class SomeContext extends Context
    {
        override public function startup():void
        {
            trace("SomeContext::startup() executed");
            
            // Map some events to Commands
            commandMap.mapEvent(ContextEvent.STARTUP, StartupCommand, ContextEvent, true);
            
            // Map some models and services
            injector.mapSingleton(SomeModel);
            injector.mapSingletonOf(ISomeService, SomeService);
            
            // Map some views
            mediatorMap.mapView(SomeView, SomeViewMediator);
            
            // Map main view (contextView) last
            // see: http://github.com/robotlegs/robotlegs-framework/blob/v1.1.2/src/org/robotlegs/base/MediatorMap.as#L117
            mediatorMap.mapView(MainView, MainViewMediator);
            
            dispatchEvent(new ContextEvent(ContextEvent.STARTUP));
        }
    }
    
    1. Is your mediator being created? Your mediator might look like this:
    public class SomeMediator extends Mediator
    {
        [Inject]
        public var view:SomeView;
        
        override public function onRegister():void
        {
            trace("SomeMediator::onRegister() executed");
            trace("View is " + view);
        }
    }
    

    Hope that helps!

  2. 2 Posted by rob on 26 Aug, 2010 12:32 PM

    rob's Avatar

    Hi Shaun,

    Thanks for a quick reply.

    Yes, my MXML file (the main application view that's created by Flex)

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
     xmlns:services="com.x.*" width="100%" pageTitle="Tester" height="100%" 
     xmlns:views="com.x.views.*" >
     .
     .
    <fx:Declarations>
    <views:GlobalContext id="globalContext" contextView="{this}" />

    I have stepped through the debugger within the context file, so yes, this has been invoked correctly, the view is mapped to the mediator last...

                // Map main view (contextView) last
            // see: http://github.com/robotlegs/robotlegs-framework/blob/v1.1.2/src/org/robotlegs/base/MediatorMap.as#L117
            mediatorMap.mapView(LoginView, LoginViewMediator);

    And the mediator looks like this...

    Oh.. .wait...

    I just notice that I registered the LoginView with the LoginViewMediator whereas I read that as MainView with my MainViewMediator, which of course wouldn't run because I never registered it!

    I'm starting to think that I might be dyslexic!! Problem solved! Thanks.

    Thanks again!
    Rob.

    package com.x.views
    {
        import org.robotlegs.mvcs.Mediator;
    
        public class HawkEyeViewMediator extends Mediator
        {
            [Inject] // This is the view that this mediator is responsible for
            public var mainView : MainView;
    
            public function MainViewMediator()
            {
                super();
            }
    
            public override function onRegister():void {
                mainView.doSomething();
            }
        }
    }
  3. Support Staff 3 Posted by Shaun Smith on 26 Aug, 2010 12:36 PM

    Shaun Smith's Avatar

    Hehe, glad you're back on track =)

  4. Shaun Smith closed this discussion on 26 Aug, 2010 12:36 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