mediatorMap.mapView() not working properly, or is it only possible in Context class?

jansensan's Avatar

jansensan

24 Jun, 2010 02:52 PM

hello, i am currently working in a project and i have an issue with dynamically loaded files. let me explain my workflow.

computer setup:
- mac os x 10.5.8 - eclipse with flash builder 4 plugin

project setup:
- flash player 9 - robot legs v1.1.1, swift suspenders v1.5.1 - i have some other embedded swcs and libraries (set as merged into code) - authoringAssets.swc (set as external) (see a bit more about this: http://jansensan.net/loading-assets-dynamically-part-2)

the issue:
so what i do, is i make sure that my assets are loaded before i map a view to a mediator. i do already map some views in the context startup() function, which work like a charm. the reason why i dont map all of them there is that some of my assets (custom classes created in the flash ide) are member variables in my view, and therefore are not available before the assets are loaded.
i thought i could map a view in a command, but when i then try to add that view to the contextView, the onRegister function is not called.

thank you if anyone can direct me to some information about this.

  1. Support Staff 1 Posted by Shaun Smith on 24 Jun, 2010 03:03 PM

    Shaun Smith's Avatar

    The mediatorMap can be used from anywhere - have a look at the source for the MVCS Command to see how it gets injected into command instances:

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

    So, the issue is probably due to something else. Can you provide some more info on how you are mapping and adding these views?

  2. 2 Posted by jansensan on 24 Jun, 2010 04:03 PM

    jansensan's Avatar

    yea, well, i guess if explain my flow? here is an overview of my classes: http://jansensan.net/images/dump/robotlegs.gif

    here is the startup for my context:

    override public function startup():void
    {
    // controller / commands
    commandMap.mapEvent (   ContextEvent.STARTUP_COMPLETE,
                                AddRootViewCommand,
                                ContextEvent,
                                true
                            );
    commandMap.mapEvent (   ReflectYourselfEvent.ROOT_VIEW_ADDED,
                                LoadConfigCommand,
                                ReflectYourselfEvent,
                                true
                            );
    commandMap.mapEvent (   ReflectYourselfEvent.CONFIG_MODEL_READY,
                                LoadAssetsCommand,
                                ReflectYourselfEvent,
                                true
                            );
    commandMap.mapEvent (   ReflectYourselfEvent.PRELOADER_ANIM_COMPLETE,
                                InitApplicationCommand,
                                ReflectYourselfEvent,
                                true
                            );
    commandMap.mapEvent (   ReflectYourselfEvent.BASIC_UI_ADDED,
                                AddPagesCommand,
                                ReflectYourselfEvent,
                                true
                            );
        
        // model
        injector.mapSingleton(AppModel);
        injector.mapSingleton(ConfigModel);
        injector.mapSingleton(AssetsModel);
        injector.mapSingleton(StateModel);
        injector.mapSingleton(FBJSBridgeModel);
        
        // view
        mediatorMap.mapView(RootView, RootMediator);
        mediatorMap.mapView(PreloaderView, PreloaderMediator);
        
        // startup
        super.startup();
    }
    

    here is the InitApplicationCommand

    override public function execute():void
    {
        stateModel.state = StateModelState.INITIALIZING;
        mediatorMap.mapView(SelectImagePage, SelectImageMediator);
    }
    

    and here is the AddPagesCommand

    override public function execute():void
    {
        contextView.addChild(new SelectImagePage());
    }
    

    so what happens is that if i trace something in the SelectImagePage constructor, it is traced, but if i try to trace something in the SelectImageMediator onRegister(), nothing happens.

  3. 3 Posted by myrddin on 24 Jun, 2010 04:25 PM

    myrddin's Avatar

    Hi,

    If I understand the problem, asolution is to replace your Class by String in mediatorMap.mapView :

    mediatorMap.mapView("swc.libray.viewClass",MediatorClass);

    In this case, you load your asset, you add your view and this view is mapped at your Mediator.

  4. 4 Posted by myrddin on 24 Jun, 2010 04:30 PM

    myrddin's Avatar

    Sorry...

    With this solution, you can map all yours views with your mediators in the Context class without importing your view classes.

  5. Support Staff 5 Posted by Shaun Smith on 24 Jun, 2010 04:31 PM

    Shaun Smith's Avatar

    Thanks for the info. I can't see anything obviously wrong with the code.. looks like it should work.

    Try adding trace(SelectImagePage) to InitApplicationCommand and AddPagesCommand, and check that both commands are referencing the same class.

  6. Support Staff 6 Posted by Shaun Smith on 24 Jun, 2010 04:33 PM

    Shaun Smith's Avatar

    @myrddin: that's definitely another option. Mapping to the fully qualified class name will work, but so should the OP's method (he is excluding the classes from being compiled into the main SWF with some compiler options).

  7. Support Staff 7 Posted by Shaun Smith on 24 Jun, 2010 04:37 PM

    Shaun Smith's Avatar

    Another thing to try: add this to both commands:

    [Inject]
    public var reflector:IReflector;
    

    And then in the commands execute methods:

    trace( reflector.getFQCN( SelectImagePage ) );
    
  8. 8 Posted by jansensan on 24 Jun, 2010 09:32 PM

    jansensan's Avatar

    Thank you for your tips, I will try on monday when I get back at work. I do want to bring some additional details: the view that I am trying to associate to a Mediator is not the one that I created in the Flash IDE

    In said Flash IDE, I created Movieclips with visual assets. Let's call them VisualAsset01 and VisualAsset02. In the SelectImagePage class, I then create member variables with those classes:

    private var someVar01:VisualAsset01;
    private var
    someVar02:VisualAsset02;

    Then in I have an public init() function in the view:

    public function init():void
    {

    _someVar01 = new VisualAsset01();
    _someVar02 = new VisualAsset02();
    

    }

    I call the init() function in the onRegister class of the Mediator, but to no avail.

    [Inject] public var view:SelectImagePage

    override public function onRegister():void
    {

    trace("--- onRegister ---");
    view.init();
    

    }

    Basically, since in Flash Builder 4 I can link to external SWF, it gives me autocomplete, but the actual assets are only loaded at runtime. I could map all views in the context, but that forces me to cast my member variables as MovieClips:

    private var someVar01:MovieClip;
    private var
    someVar02:MovieClip;

    This then works, but I lose autocomplete, not practical. That is why I want to map my views only when my assets are loaded, so that I do not obtain an error at runtime saying that my classes are missing.

    I unfortunately do not have the sources with me now, but as soon as I do (Monday) I'll provide a barebone example, maybe that will guide you to help me?

  9. 9 Posted by jansensan on 28 Jun, 2010 08:42 AM

    jansensan's Avatar

    hello all, here i provide an example package of how i worked in this project, so it may help people understand where i may have not worked properly. thanks again

  10. Support Staff 10 Posted by Shaun Smith on 28 Jun, 2010 11:06 PM

    Shaun Smith's Avatar

    You need to map the mediator before you add it to the stage:

     [object InitApplicationCommand] --- execute ---
     [object RootMediator] --- basicUIAddedHandler ---
     [object AddPagesCommand] --- execute ---
    AddPagesCommand - About to add new SelectImagePage..
     [object SelectImagePage] --- constructor ---
    AddPagesCommand - new SelectImagePage added
    InitApplicationCommand - About to map mediator..
    InitApplicationCommand - Mediator mapped
    

    Notice that the mediator is mapped after the view component has been added to the stage.

    Your InitApplicationCommand calls stateModel.state = StateModelState.INITIALIZING; before mapping the mediator:

        override public function execute():void
        {
            trace("\n", this, "--- execute ---");
            
            stateModel.state = StateModelState.INITIALIZING;
            
            trace('InitApplicationCommand - About to map mediator..');
            mediatorMap.mapView(SelectImagePage, SelectImageMediator);
            trace('InitApplicationCommand - Mediator mapped');
        }
    

    You should be mapping the mediator before setting the model state:

        override public function execute():void
        {
            trace("\n", this, "--- execute ---");
            
            trace('InitApplicationCommand - About to map mediator..');
            mediatorMap.mapView(SelectImagePage, SelectImageMediator);
            trace('InitApplicationCommand - Mediator mapped');
            
            stateModel.state = StateModelState.INITIALIZING;
        }
    

    Which sorts your problem out:

    [object InitApplicationCommand] --- execute ---
    InitApplicationCommand - About to map mediator..
    InitApplicationCommand - Mediator mapped
     [object RootMediator] --- basicUIAddedHandler ---
     [object AddPagesCommand] --- execute ---
    AddPagesCommand - About to add new SelectImagePage..
     [object SelectImagePage] --- constructor ---
     [object SelectImageMediator] --- onRegister ---
     [object SelectImagePage] --- init ---
    AddPagesCommand - new SelectImagePage added
    
  11. 11 Posted by jansensan on 29 Jun, 2010 08:04 AM

    jansensan's Avatar

    whoa! what an overlook on my part! i makes so much sense, but i guess i was not looking at the right place at all. thanks so much for helping me out!

  12. Support Staff 12 Posted by Shaun Smith on 29 Jun, 2010 02:35 PM

    Shaun Smith's Avatar

    No problem, glad you're back on track.

  13. Shaun Smith closed this discussion on 29 Jun, 2010 02:35 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