Mediators stopped working all of a sudden

kamcknig's Avatar

kamcknig

25 Aug, 2015 11:59 AM

Hello!

So I've been working with RL2 for a bit now. And my project was going just fine. I was changing some views around, just changing some widths and heights and repositioning them and then all of a sudden everything just stopped working up to a certain point. My mediators no longer got created and intialized. I have literally no idea where to go to debug it. I can't even setup a simple project to show what's happening as it's specific to this project. I really dont think I cahnged anything at all having to do with the config. I have a MainView that has some children are a part of it's MXML. Some of those children are mediated. MainView gets mediated just fine. I've added and Event.ADDED listener to MainView and the children that are supposed to be mediated are added to the stage according to the traces from the ADDED handler, but the mediators for them are no longer being created! The only code I've changed was width/height/position code.

My code is also under revisiion control and I stashed all changes I had made since I knew it was working, and it is still doing the same thing. So it literally CANNOT be my code that made it stop working.

No clue where to even begin to look. If this sort of thing has happened to anyone else and you were able to fix it, please let me know!

Thanks!

  1. 1 Posted by kamcknig on 25 Aug, 2015 12:21 PM

    kamcknig's Avatar

    I've also added an ADDED_TO_STAGE event handler for the view that isn't getting mediated, and that handler gets fired, but RL2 still isn't creating the mediator for it. I've tripled checked my config and nothing changed there, it's still properly mapping that view to it's mediator.

  2. 2 Posted by kamcknig on 25 Aug, 2015 12:23 PM

    kamcknig's Avatar

    Also tried to manually mediate the view after it was created using mediatorMap.mediate() and the mediator still doesn't get initialized.

    Though views earlier in the startup of the app mediate just fine still

  3. Support Staff 3 Posted by Ondina D.F. on 25 Aug, 2015 12:31 PM

    Ondina D.F.'s Avatar

    Hi,

    Let's start with a few common problems:

    • are you compiling against the the robotlegs source?
    • are you keeping a reference to your context?

    See:
    - https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble... - https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...

    I was changing some views around, just changing some widths and heights and repositioning them and then all of a sudden everything just stopped working up to a certain point.

    Does this mean that the views are repositioned at run time or do you mean you changed the code for those properties?

    I've added and Event.ADDED listener to MainView and the children that are supposed to be mediated are added to the stage according to the traces from the ADDED handler, but the mediators for them are no longer being created!

    Could you also add a listener for the removed from stage event? I'm asking that because if you are repositioning the views dynamically, and if you are using Flex, it may be that the components are first removed from stage before they are placed (added to the stage) at the new position.

    Can you also show the mapping for the views/mediators in question?

    Can you tell me what kind of a project that is, Flex, AIR, as3?

  4. Support Staff 4 Posted by Ondina D.F. on 25 Aug, 2015 12:36 PM

    Ondina D.F.'s Avatar

    Oh, I see it's flex, since you're using mxml

  5. 5 Posted by kamcknig on 25 Aug, 2015 12:48 PM

    kamcknig's Avatar

    I'm using this as my code to startup RL2 in my document class. Do I need to store the context elsewhere?

    <fx:Declarations>
        <rl2:ContextBuilder>
            <mvcs:MVCSBundle/>
            <config:MyAppConfig/>
        </rl2:ContextBuilder>
    </fx:Declarations>
    

    Does this mean that the views are repositioned at run time or do you mean you changed the code for those properties?

    I am just changing some properties on the views in MXML.

    Could you also add a listener for the removed from stage event?

    I went ahead and did that but I never get the trace that the handler is called so I don't think it's being removed.

    Can you also show the mapping for the views/mediators in question?

    I have a MainView that is mapped and that mapping works fine. In MainViewMediator I listen for a context event and in that handler, I create a new NewView and add it to MainView. This is where my trace for added to stage works for NewView but the mediator is never created. And this was working fine literally between two compiles where all I did was change heights/widths of some of the views (in MXML).

    Mappings in my config

    mediatorMap.map(MainView).toMediator(MainViewMediator);
    mediatorMap.map(NewView).toMediator(NewView);
    

    MainViewMediator handler to add NewView

    //in intiialize
    addContextListener(DisplayViewEvent.DISPLAY_VIEW, handleDisplayView, DisplayViewEvent);
    
    //in handleDisplayView
    switch(viewId)
    {
        case ViewTypes.POINT_OF_SALE_VIEW:
            newView = new PointOfSaleView();
            break;
    }
                
    newView.top = 46;
    newView.right = 5;
    newView.bottom = 30;
    newView.left = 5;
                
    view.addElement(newView);
    

    And I also tried like I said injecting the IMediatorMap into my MainViewMediator and after adding newView, tried mapping it manually and the mediator was still never created/initialized

  6. 6 Posted by kamcknig on 25 Aug, 2015 12:52 PM

    kamcknig's Avatar

    I added a constructor to the mediator in question. It DOES get created as the constructor is called. But the initilize is never called. and none of that view's children that are also mediated get theire initailize functions called. I added a constructor to a random mediator for one of NewView's children's mediator and it's constructor also gets called. so it's just the initalize function sthat aren't happening.

    Also, the views themselves aren't even showing up on the stage even though they say they are being added.

    I almost feel like I just need to destory the project and recreate it. Maybe it's some weird workspace issue. I'm using FlashDevelop. But I've never seemed to have had a problem like this before.

  7. Support Staff 7 Posted by Ondina D.F. on 25 Aug, 2015 12:59 PM

    Ondina D.F.'s Avatar

    Take a deeeeeeep breath:)
    Let's slow down and try things step by step.

    Try

    • adding a NewView directly from the MainView

    • include the NewView as mxml in the MainView

  8. Support Staff 8 Posted by Ondina D.F. on 25 Aug, 2015 01:12 PM

    Ondina D.F.'s Avatar

    mediatorMap.map(NewView).toMediator(NewView);

    You're mapping a NewView to a NewView instead of a NewViewMediator. But maybe that was just a typo when you wrote the message.

    You're creating a new PointOfSaleView, but there is no mapping for PointOfSaleView.

  9. 9 Posted by kamcknig on 25 Aug, 2015 01:18 PM

    kamcknig's Avatar

    Haha, INnnnnnnhale.... exhhhhhalllllleeee

    Same results :) The traces for the added and the traces for the mediators' constructors get called, but not the initialize methods

    Sorry the NewView to NewView was a typo, I do actually have NewViewMediator.

    well actually it's PointOfSaleView and PointOfSaleViewMediator, I was just using NewView as a shorter name

  10. 10 Posted by kamcknig on 25 Aug, 2015 01:22 PM

    kamcknig's Avatar

    Ummmmm ok. So. One of the children of PointOfSaleView, ChildViewA, has five child components itself. I added a VGroup around those five components. And that's when this problem happens. I removed that VGroup annnnnd everything is fixed....

  11. Support Staff 11 Posted by Ondina D.F. on 25 Aug, 2015 01:24 PM

    Ondina D.F.'s Avatar

    Hey, I didn't say exhale yet :P

    So, exhale!

    Also, the views themselves aren't even showing up on the stage even though they say they are being added.

    If the views are not visible, something is wrong....

    Can you create a very simple view with a very simple mediator, and add that view to the MainView?

  12. Support Staff 12 Posted by Ondina D.F. on 25 Aug, 2015 01:25 PM

    Ondina D.F.'s Avatar

    I added a VGroup around those five components. And that's when this problem happens. I removed that VGroup annnnnd everything is fixed....

    It seems that the views get re-parented.

  13. 13 Posted by kamcknig on 25 Aug, 2015 01:31 PM

    kamcknig's Avatar

    It seems that the views get re-parented.

    I'm not sure that I understand what that means in this context and why it breaks it :/

  14. Support Staff 14 Posted by Ondina D.F. on 25 Aug, 2015 01:40 PM

    Ondina D.F.'s Avatar

    Short answer:
    When a component is re-parented, Flex is removing it from stage before adding it to the new parent container, as I mentioned above.
    If a view is removed from stage, its mediator is also removed.

    Here details about Flex - reparenting and components' state changes:
    http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c...

  15. 15 Posted by kamcknig on 25 Aug, 2015 01:43 PM

    kamcknig's Avatar

    Hmm, OK, but those remove handlers were never being called. And when they are re-added shouldn't RL2 then recreate/initialize the mediators?

  16. Support Staff 16 Posted by Ondina D.F. on 25 Aug, 2015 01:44 PM

    Ondina D.F.'s Avatar
  17. Support Staff 17 Posted by Ondina D.F. on 25 Aug, 2015 01:45 PM

    Ondina D.F.'s Avatar

    Have you tried to add a simple view with a simple mediator already....?
    A view with no states, no specified positions, etc.

  18. 18 Posted by kamcknig on 25 Aug, 2015 01:48 PM

    kamcknig's Avatar

    This view in question doesn't have states (at least none explicitly defined by me. And the overall component it's based on is simply a Group)

  19. 19 Posted by kamcknig on 25 Aug, 2015 01:49 PM

    kamcknig's Avatar

    I'm not sure why this would affect it anyway as I'm not doing it dynamically. The VGroup was just added in MXML. There are hundreds of VGroups/HGroups and such elsewhere surrounding other componets in other classes and it works fine in those. This is why I hate Flex. So wish I could just do this in pure ActionScript :)

  20. Support Staff 20 Posted by Ondina D.F. on 25 Aug, 2015 01:50 PM

    Ondina D.F.'s Avatar

    Yeah, but make an effort and do add a simple view as I said:)

  21. Support Staff 21 Posted by Ondina D.F. on 25 Aug, 2015 01:54 PM

    Ondina D.F.'s Avatar

    Do so:

    In main view add a handler for the added to stage event.
    Inside that handler do:

    var someView:SomeView = new SomeView();
    addElement(someView);

    where someView is a simple Group.
    Create a SomeMediator.
    Map SomeView to SomeMediator.

    Tell me what happens.

  22. Support Staff 22 Posted by Ondina D.F. on 25 Aug, 2015 02:03 PM

    Ondina D.F.'s Avatar

    I'm not sure why this would affect it anyway as I'm not doing it dynamically. The VGroup was just added in MXML.

    Well, in your previously posted code you added the new view to the view itself (MainView), not to the VGroup. MainView is probably the windowed application, right?
    You're adding newView dynamically, but maybe not to the right parent container.

    Too bad I can't see your code, because I'm sure I'd find the culprit. There is something trivial going on, but it's hard to tell what that is from here.

  23. 23 Posted by kamcknig on 25 Aug, 2015 02:05 PM

    kamcknig's Avatar

    OK If I did it in the correct wat that you wanted me to it works just fine.

    Created DummyView.mxml that is just an empty spark Group.

    In MainView, added event handler for ADDED_TO_STAGE and in the handler, created new DummyView and added it.

    In config file mapped a DummyViewMediator to DummyView.

    I traced out the constructor and intiailize of DummyViewMediator and it all works fine

  24. 24 Posted by kamcknig on 25 Aug, 2015 02:07 PM

    kamcknig's Avatar

    Ah sorry, no, my structure as of now is

    WindowedApplication
    ---> MainView
    --->--->PointOfSaleView
    --->--->--->KeywordListView
    --->--->--->PackageListView
    --->--->--->--->Child1
    --->--->--->--->Child2
    --->--->--->--->Child3
    --->--->--->--->Child4
    

    If I wrap Child1-4 in a VGroup it all breaks

  25. Support Staff 25 Posted by Ondina D.F. on 25 Aug, 2015 02:11 PM

    Ondina D.F.'s Avatar

    I traced out the constructor and intiailize of DummyViewMediator and it all works fine

    Ok, now try to add PointOfSaleView to the stage exactly like the DummyView.

  26. 26 Posted by kamcknig on 25 Aug, 2015 02:15 PM

    kamcknig's Avatar

    Actually to be more accurate I would be wrapping Child3 and Child4 in a VGroup

  27. 27 Posted by kamcknig on 25 Aug, 2015 02:17 PM

    kamcknig's Avatar

    OK If I add PointOfSaleView the same way as DummyView then it still all works (this is without the VGroup by the way).

  28. Support Staff 28 Posted by Ondina D.F. on 25 Aug, 2015 02:20 PM

    Ondina D.F.'s Avatar

    Now, add the PointOfSaleView to the VGroup (id="vGroup" for the sake of an example) instead of the MainView

    vGroup.addElement( new PointOfSaleView());

  29. 29 Posted by kamcknig on 25 Aug, 2015 02:25 PM

    kamcknig's Avatar

    After adding PointOfSaleView to MainView, add it to a vGroup within MainView? or just add it directly to VGroup first?

  30. Support Staff 30 Posted by Ondina D.F. on 25 Aug, 2015 02:26 PM

    Ondina D.F.'s Avatar

    directly to vgroup

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