title: how do I dynamically map view to mediator in Haxe using Cube framework
body: <p>I've been working with and learning the following micro framework Cube <a href="https://github.com/xirsys/cube" rel="nofollow noreferrer">https://github.com/xirsys/cube</a> for use in my Haxe projects.</p>
  
  <p>The examples I've found have been very helpful but one thing the examples that I've ran across don't have that I'd like to figure out is registering and mapping views to mediators at runtime.</p>
  
  <p>I think I'm close but it just doesn't seem to be working. Heres what my AppContext looks like.</p>
  
  <pre><code>class AppContext extends Agent&lt;Dynamic, IEvent&gt; 
  {
      public function new(container: Dynamic, autoStart:Bool)
      {
          super(container, autoStart);
      }
  
      override public function initiate()
      {
          mediatorMap.mapView(Main, MainMediator);
          mediatorMap.mapView(Welcome, WelcomeMediator);
  
          injector.mapSingleton(AppModel, container);
          dispatch(AgentEvent.STARTUP_COMPLETE, null);
      }
  }
  </code></pre>
  
  <p>here is what's going on my my Main view</p>
  
  <pre><code>class Main extends Sprite
  {
      public var agent: AppContext;
  
      @Inject
      public var dm:AppModel;
  
      public function new()
      {
          super();
          addEventListener(Event.ADDED_TO_STAGE, onAdded);
          haxe.Log.setColor(0xffffff);
          this.name = "main view";
      }
  
      public static function main(): Void
      {
          Lib.current.addChild(new Blastroidz());
      }
  
      private function onAdded(e:Event):Void
      {
          agent = new AppContext(this, false);
          agent.addEventHandler(AgentEvent.STARTUP_COMPLETE, onContextStart);
          agent.initiate();
  
      }
  
      private function onContextStart(evt:IEvent):Void
      {
          agent.mediatorMap.createMediator(this);
      }
  
  }
  </code></pre>
  
  <p>Now after the main view loads up in my Main view Mediator I create the "welcome" view and then I would like to create it's mediator and use it like so.</p>
  
  <pre><code>class MainMediator extends xirsys.cube.mvcs.Mediator
  {
      @Inject
      public var view:Main;
      public var welcome:Welcome;
      private var viewManager:NMEViewManager;
  
      override public function onRegister()
      {
          super.onRegister();     
          eventDispatcher.addEventHandler(AppEvent.SET_NEW_VIEW, changeViewHandler);
          initView();
      }
  
      private function initView():Void
      {
          viewManager = new NMEViewManager(view);
          welcome = new Welcome();
  
          viewManager.setView(welcome, NMEViewManager.FADE);
  
              ///// this is the important line that doesn't seem to work \\\\\\
          mediatorMap.createMediator(welcome);
      }
  
      private function changeViewHandler(e:String):Void
      {
          trace("change view");
      }
  </code></pre>
  
  <p>My welcome mediator looks like so and the onRegister doesn't seem to fire and I don't get any errors at all .... note that viewManager handles addChild to the main view of the welcome view and this seems to work just fine. </p>
  
  <pre><code>class WelcomeMediator extends xirsys.cube.mvcs.Mediator 
  {
      @Inject
      public var view:Welcome;
  
      override public function onRegister()
      {
          super.onRegister();
          view.addEventListener(Event.COMPLETE, onCompleteHandler);
          trace("welcome mediator registered");
      }
  
      private function onCompleteHandler(e:Event):Void
      {
          trace("logo complete");
          var event:AppEvent = new AppEvent(AppEvent.SET_NEW_VIEW);
          event.view_name = AppModel.MAIN;
  
          this.eventDispatcher.dispatch(AppEvent.SET_NEW_VIEW, event);
      }
  }
  
  
  
  }
  </code></pre>