Pure AS3 Modular Robotlegs Project (1000: Ambiguous reference to commandMap, mediatorMap)

derekdon's Avatar

derekdon

06 Jun, 2010 04:45 PM

1000: Ambiguous reference to * is driving me nuts...

If the shells context extends Context there's no problem, but since it's a modular app the shell is meant to extend ModuleContext right?

My run file / shell:

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.system.Security;
    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell.PrintEditorContext;

    public class RoboPrintEditor 
    extends Sprite
    {
        private var _context:PrintEditorContext;

        public function RoboPrintEditor()
        {
            super();

            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            trace("Hello from RoboPrintEditor");

            //Security.allowDomain("maps.googleapis.com");

            // initialize the framework
            _context = new PrintEditorContext(this);
        }
    }
}

it's context:

package com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell
{
    import flash.display.DisplayObjectContainer;
    import org.robotlegs.core.IInjector;
    import flash.system.ApplicationDomain;
    import org.robotlegs.utilities.modular.mvcs.ModuleContext;
    import org.robotlegs.mvcs.Context;
    import org.robotlegs.base.ContextEvent;
    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell.controller.config.BootstrapAppCommand;

    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.modules.logger.LoggerModule;

    public class PrintEditorContext 
    extends ModuleContext
    {
        public function PrintEditorContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true, parentInjector:IInjector = null, applicationDomain:ApplicationDomain = null)
        {
            super(contextView, autoStartup, parentInjector, applicationDomain);
        }

        override public function startup():void
        {
            // How can I move these into one of the commands since the context needs to be referenced?          
            //map the modules so that instances will be properly supplied (injected) with an injector.
            viewMap.mapType(LoggerModule);

            //Map Configuration Commands
            //moduleCommandMap.mapEvent(ContextEvent.STARTUP, BootstrapAppCommand, ContextEvent, true);
            commandMap.mapEvent(ContextEvent.STARTUP, BootstrapAppCommand, ContextEvent, true);

            //Start the Application
            //dispatchToModules(new ContextEvent(ContextEvent.STARTUP));
            dispatchEvent(new ContextEvent(ContextEvent.STARTUP));
        }
    }
}

BootstrapAppCommand:

package com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell.controller.config
{
    import org.robotlegs.utilities.modular.mvcs.ModuleCommand;
    import org.robotlegs.base.ContextEvent;
    import org.robotlegs.utilities.statemachine.FSMInjector;
    import org.robotlegs.utilities.statemachine.StateEvent;
    import org.robotlegs.utilities.statemachine.StateMachine;
    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell.AppConfigStateConstants;
    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell.controller.load.LoadResourcesCommand;

    public class BootstrapAppCommand 
    extends ModuleCommand
    {
        [Inject]
        public var event:ContextEvent;

        override public function execute():void
        {
            try
            {
                // Setup FSM
                var fsmInjector:FSMInjector = new FSMInjector(AppConfigStateConstants.FSM);
                var stateMachine:StateMachine = new StateMachine(eventDispatcher);

                // Map the commands for the state machine. All states in the machine are mapped to a specific command that is triggered in order 
                commandMap.mapEvent(AppConfigStateConstants.CONFIGURE_COMMANDS, ConfigureCommandsCommand,   StateEvent, true);
                commandMap.mapEvent(AppConfigStateConstants.CONFIGURE_DATABASES, ConfigureDatabasesCommand, StateEvent, true);
                commandMap.mapEvent(AppConfigStateConstants.CONFIGURE_SERVICES, ConfigureServicesCommand,   StateEvent, true);
                commandMap.mapEvent(AppConfigStateConstants.CONFIGURE_MODELS,   ConfigureModelsCommand,     StateEvent, true);
                commandMap.mapEvent(AppConfigStateConstants.CONFIGURE_VIEWS,    ConfigureViewsCommand,      StateEvent, true);
                commandMap.mapEvent(AppConfigStateConstants.LOAD_RESOURCES,     LoadResourcesCommand,       StateEvent, true);
                commandMap.mapEvent(AppConfigStateConstants.NAVIGATE,           NavigateCommand,            StateEvent, true);
                commandMap.mapEvent(AppConfigStateConstants.FAIL,               ConfigurationFailedCommand, StateEvent, true);

                // Injecting the state machine into the FSMInjector
                fsmInjector.inject(stateMachine);

                // Start the state machine!!!
                eventDispatcher.dispatchEvent(new StateEvent(StateEvent.ACTION, AppConfigStateConstants.STARTED));
            }
            catch(e:Error)
            {
                eventDispatcher.dispatchEvent(new StateEvent(StateEvent.ACTION, AppConfigStateConstants.START_FAILED));
            }
        }
    }
}

I've been messing around with the logger module in found in some of Joel Hooks examples, in my LoggerModuleContext I get the same Ambiguous reference errors!

package com.derekdonnelly.widgets.mage.product.printable.roboeditor.modules.logger
{
    import flash.display.DisplayObjectContainer;

    import org.robotlegs.core.IInjector;
    import org.robotlegs.utilities.modular.mvcs.ModuleContext;

    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.modules.logger.view.LoggerModuleMediator;

    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.common.events.LoggingEvent;
    //import com.derekdonnelly.widgets.mage.product.printable.roboeditor.common.events.ModuleCommandTriggerEvent;

    public class LoggerModuleContext 
    extends ModuleContext
    {
        public function LoggerModuleContext(contextView:DisplayObjectContainer, injector:IInjector)
        {
            super(contextView, true, injector);
        }

        override public function startup():void
        {
            mediatorMap.mapView(LoggerModule, LoggerModuleMediator);

            dispatchToModules(new LoggingEvent(LoggingEvent.MESSAGE, "New Logger Added"));
        }

        override public function dispose():void
        {
            mediatorMap.removeMediatorByView(contextView);

            super.dispose();
        }
    }
}

Here is the LoggerModule for ref:

package com.derekdonnelly.widgets.mage.product.printable.roboeditor.modules.logger
{
    import org.robotlegs.core.IInjector;
    import org.robotlegs.utilities.modular.core.IModule;
    import org.robotlegs.utilities.modular.core.IModuleContext;

    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell.interfaces.IPalette;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.geom.Rectangle;
    import fl.controls.Label;
    import fl.controls.TextInput;
    import fl.controls.Button;

    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.shell.events.PaletteEvent;
    import com.derekdonnelly.widgets.mage.product.printable.roboeditor.common.events.LoggingEvent;

    // Class meta data
    [Event(name="LoggingEvent.MESSAGE", type="com.derekdonnelly.widgets.mage.product.printable.roboeditor.common.events.LoggingEvent")]

    [Embed(source='media/swf/lib/palettes.swf', symbol='Logger')]
    public class LoggerModule
    extends MovieClip
    implements IModule, IPalette
    {
        private var _context:IModuleContext;
        private var _title:String = "Logger";
        private var _initialized:Boolean = false;

        [Bindable(event="propertyChange", type="mx.events.PropertyChangeEvent")]
        public var active:Boolean = false;

        [Bindable(event="propertyChange", type="mx.events.PropertyChangeEvent")]
        public var messages:String = "";

        public var label:Label;
        public var logOutput:TextInput;
        public var clear_btn:Button;
        public var save_btn:Button;
        public var closePalette_mc:MovieClip;
        public var bg_mc:MovieClip;

        public function LoggerModule()
        {
            super();
        }

        public function init():void
        {
            _initView();
            _initBehaviour();
            _initialized = true;
        }

        public function get initialized():Boolean { return _initialized }

        public function get closeButtonRect():Rectangle
        {
            return new Rectangle(closePalette_mc.x, closePalette_mc.y, closePalette_mc.width, closePalette_mc.height);
        }

        public function open():void
        {
            visible = true;
            dispatchEvent(new Event(PaletteEvent.OPEN));
        }

        public function expand():void {};
        public function collapse():void {};

        public function close():void
        {
            visible = false;
        }

        public function set title(val:String):void
        {
            if(label) label.text = val;
            _title = val;
        }

        public function clearLog():void
        {
            logOutput.text = "";
        }

        public function saveLog():void
        {
        }

        private function _handleEvent(event:*):void
        {
            switch(event.type)
            {
                case MouseEvent.MOUSE_UP:
                    if(event.target == closePalette_mc)
                    {
                        close();
                        dispatchEvent(new Event(PaletteEvent.CLOSE));
                    }
                break;
                case MouseEvent.CLICK:
                    switch(event.target)
                    {
                        case clear_btn:
                            clearLog();
                            dispatchEvent(new LoggingEvent(LoggingEvent.CLEAR, "Logger Cleared"));
                        break;
                        case save_btn:
                            saveLog();
                            dispatchEvent(new LoggingEvent(LoggingEvent.SAVE, "Logger Saved"));
                        break;
                    }
                break;
            }
        }

        private function _addButton(name:String, label:String, x:Number = 0, y:Number = 0, width:Number = 50):Button
        {
            var btn:Button = new Button();
            btn.name = name;
            btn.label = label;
            btn.x = x;
            btn.y = y;
            btn.width = width;
            addChild(btn);
            return btn;
        }

        private function _initView():void
        {
            x = 300;
            y = 800;

            closePalette_mc.buttonMode = true;

            label = new Label();
            label.name = "label";
            label.text = _title;
            label.autoSize = "left";
            label.move(18, 16);
            addChild(label);

            logOutput = new TextInput(); // Testing. This should be a TextArea. The added AS3 comp lib doesn't seem to have it.
            logOutput.name = "logOutput";
            logOutput.move(20, 41);
            logOutput.setSize(323, 96);
            addChild(logOutput);

            clear_btn = _addButton("clear_btn", "Clear", 20, 146, 75);
            save_btn = _addButton("save_btn", "Save", 105, 146, 75);

            visible = false;
        }

        private function _initBehaviour():void
        {
            closePalette_mc.addEventListener(MouseEvent.MOUSE_UP, _handleEvent);
            clear_btn.addEventListener(MouseEvent.CLICK, _handleEvent);
            save_btn.addEventListener(MouseEvent.CLICK, _handleEvent);
        }

        public function addLoggingMessage(message:String):void
        {
            message += "\r";
            messages += message;
            scrollToMax();
        }

        private function scrollToMax():void
        {
            logOutput.validateNow();
            //logOutput.scroller.verticalScrollBar.value = logOutput.scroller.verticalScrollBar.maximum;            
        }

        /**
         * We need to initialize our context by setting the parent
         * injector for the module. This is actually injected by the
         * shell, so no need to worry about it!
        */
        [Inject]
        public function set parentInjector(value:IInjector):void
        {
            _context = new LoggerModuleContext(this, value);
        }

        public function dispose():void
        {
            _context.dispose();
            _context = null;
        }
    }
}

If I just use the moduleCommandMap and dispatchToModules methods when the shell's context extends ModuleContext, then there's no error, but I still get the Ambiguous reference errors for the mediatorMap in the LoggerModuleContext. Also I think I should be just using the commandMap and dispatchEvent in the shell's context as the modules don't need to know about the build process.

I am using Joel's fork of the Modular utility etc.

I really need to figure this out asap...

Thanks guys,

Derek.

  1. Support Staff 1 Posted by Joel Hooks on 06 Jun, 2010 05:45 PM

    Joel Hooks's Avatar

    Can you post a zip of this so I can actually run it? You can also email it to me if that is better. It is hard to say what is breaking out of context.

  2. 2 Posted by derekdon on 06 Jun, 2010 07:17 PM

    derekdon's Avatar

    Thanks Joel, emailing you shortly. Derek.

  3. 3 Posted by derekdon on 07 Jun, 2010 04:21 PM

    derekdon's Avatar

    Problem shorted with a small Modular util fix... Cheers Joel!

  4. Support Staff 4 Posted by Joel Hooks on 07 Jun, 2010 04:26 PM

    Joel Hooks's Avatar

    It seems so silly that it won't honor the overriding of JUST a getter ;) - glad we got it worked out!

  5. Joel Hooks closed this discussion on 07 Jun, 2010 04: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