startup method not getting called in modular contexts

tom's Avatar

tom

29 May, 2010 12:38 AM

a context extending ModuleContext does not getting it's overriden startup method called.
injection mapping and event dispatching (to the core) is working fine, though - i'm calling the startup method from the constructor of the modular context to work around this for now.
intended - or am i missing something?

  1. 1 Posted by tom on 04 Jun, 2010 09:28 PM

    tom's Avatar

    due to this issue i need to call startup() in the context's constructor to get the mapping done. unfortunately, this seems to be too early. every few reloads of the same swf commands mapped using moduleCommandMap.mapEvent() won't get triggered.

    this seems only to be the case when the event gets dispatched from a ModuleMediator using dispatchToModule() - it's call to moduleDispatcher.hasEventListener() returns false when the command isn't getting called.

    please assist, thank you.

  2. Support Staff 2 Posted by Joel Hooks on 04 Jun, 2010 09:34 PM

    Joel Hooks's Avatar

    You're gonna need to post some code Tom. The startup method DOES get called, but there is some weirdness revolving around ADDED_TO_STAGE and the startup method in the base Context.

  3. Support Staff 3 Posted by Joel Hooks on 04 Jun, 2010 09:35 PM

    Joel Hooks's Avatar

    When I say does it called, it does in my examples, so there is something happening in your application that is blocking it.

  4. 4 Posted by tom on 04 Jun, 2010 10:00 PM

    tom's Avatar

    i've implemented my code following your tutorial at http://joelhooks.com/2010/05/02/modular-robotlegs/

    module's main class

    <?xml version="1.0" encoding="utf-8"?>
    
    
        <![CDATA[
            import net.ip8.FoobarConnectorContext;
    
            import org.robotlegs.core.IInjector;
            import org.robotlegs.utilities.modular.core.IModuleContext;
    
            protected var context : IModuleContext;
    
            [Inject]
            public function set parentInjector(value : IInjector) : void {
                context = new FoobarConnectorContext(this, value);
            }
    
            public function dispose() : void {
                context.dispose();
                context = null;
            }
            ]]>
    

    and the context

    package net.ip8
    {
        import flash.display.DisplayObjectContainer;
    
    ...
    
        import org.robotlegs.base.ContextEvent;
        import org.robotlegs.core.IInjector;
        import org.robotlegs.utilities.modular.mvcs.ModuleContext;
    
        public class FoobarConnectorContext extends ModuleContext
        {
            public function FoobarConnectorContext(contextView : DisplayObjectContainer, injector : IInjector, autoStart : Boolean = true) {
                super(contextView, autoStart, injector);
    
                // FIXME
                startup();
            }
    
            override public function startup() : void {
                injector.mapSingletonOf(IPeerConnector, FMS4Connector);
    
                moduleCommandMap.mapEvent(PeerConnectorEvent.CONNECT, ConnectPeerCommand, PeerConnectorEvent);
                moduleCommandMap.mapEvent(PeerConnectorEvent.CONNECTED, PeerConnectedComand, PeerConnectorEvent);
                moduleCommandMap.mapEvent(PeerConnectorEvent.DISCONNECTED, PeerDisconnectedCommand, PeerConnectorEvent);
    
                commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, StartupCommand, ContextEvent, true);
    
                super.startup();
            }
    
            override public function dispose() : void {
                mediatorMap.removeMediatorByView(contextView);
                super.dispose();
            }
        }
    }
    

    and the mediator (from the application)

    package net.ip8.moduleManager.mediator
    {
    ..
        import org.robotlegs.utilities.modular.mvcs.ModuleMediator;
    
        public class ModuleManagerViewMediator extends ModuleMediator
        {
            [Inject]
            public var view : ModuleManagerView;
    
            public function ModuleManagerViewMediator() {
                super();
            }
    
            override public function onRegister() : void {
                eventMap.mapListener(view.connectButton, MouseEvent.CLICK, handleConnectButtonClick, MouseEvent);
            }
    
            private function handleConnectButtonClick(event : MouseEvent) : void {
                var connectPeerEvent : PeerConnectorEvent = new PeerConnectorEvent(PeerConnectorEvent.CONNECT);
                dispatchToModules(connectPeerEvent);
            }
        }
    }
    

    when autoStartup is set to false the command will never get called, set to true works sometimes (per reload).

    pretty strange, guess you are right, something related to ADDED_TO_STAGE.

  5. 5 Posted by tom on 04 Jun, 2010 10:21 PM

    tom's Avatar

    i should add that each module is compiled to a separate SWF. application and modules only share some events. thinking over this again i just realized that the modular views are never added to stage as the main application does not declare them - quite logical that this results in startup() not being called.

    i'd like to keep code sharing down to a minimum. guess i need to find a way to manually call the startup method from inside the module or add the module to the display list.

  6. Support Staff 6 Posted by Joel Hooks on 04 Jun, 2010 11:41 PM

    Joel Hooks's Avatar

    http://github.com/robotlegs/robotlegs-framework/blob/master/src/org...

    Here is the method in the mvcs context that is likely bullying you. I'm actually surprised that calling startup after super in your constructor is failing. Perhaps overriding checkAutoStartup() in your context and just calling startup there would do the trick? It is about the same thing really, but perhaps a little more explicit.

  7. 7 Posted by tom on 08 Jun, 2010 11:27 AM

    tom's Avatar

    hell yeah that's working. thanks a million!

       override public function startup() : void {
            // ...
            super.startup();
        }
    
        override protected function checkAutoStartup() : void {
            startup();
        }
    
  8. 8 Posted by tom on 09 Jun, 2010 10:25 AM

    tom's Avatar

    doh, i got happy too early, the command isn't getting mapped every now and then.

  9. Stray closed this discussion on 10 Feb, 2011 05:26 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