Mediators stopped working all of a sudden
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!
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
1 Posted by kamcknig on 25 Aug, 2015 12:21 PM
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 Posted by kamcknig on 25 Aug, 2015 12:23 PM
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
Support Staff 3 Posted by Ondina D.F. on 25 Aug, 2015 12:31 PM
Hi,
Let's start with a few common problems:
See:
- https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble... - https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...
Does this mean that the views are repositioned at run time or do you mean you changed the code for those properties?
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?
Support Staff 4 Posted by Ondina D.F. on 25 Aug, 2015 12:36 PM
Oh, I see it's flex, since you're using mxml
5 Posted by kamcknig on 25 Aug, 2015 12:48 PM
I'm using this as my code to startup RL2 in my document class. Do I need to store the context elsewhere?
I am just changing some properties on the views in MXML.
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.
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
MainViewMediator handler to add 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 Posted by kamcknig on 25 Aug, 2015 12:52 PM
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.
Support Staff 7 Posted by Ondina D.F. on 25 Aug, 2015 12:59 PM
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
Support Staff 8 Posted by Ondina D.F. on 25 Aug, 2015 01:12 PM
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 Posted by kamcknig on 25 Aug, 2015 01:18 PM
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 Posted by kamcknig on 25 Aug, 2015 01:22 PM
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....
Support Staff 11 Posted by Ondina D.F. on 25 Aug, 2015 01:24 PM
Hey, I didn't say exhale yet :P
So, exhale!
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?
Support Staff 12 Posted by Ondina D.F. on 25 Aug, 2015 01:25 PM
It seems that the views get re-parented.
13 Posted by kamcknig on 25 Aug, 2015 01:31 PM
I'm not sure that I understand what that means in this context and why it breaks it :/
Support Staff 14 Posted by Ondina D.F. on 25 Aug, 2015 01:40 PM
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 Posted by kamcknig on 25 Aug, 2015 01:43 PM
Hmm, OK, but those remove handlers were never being called. And when they are re-added shouldn't RL2 then recreate/initialize the mediators?
Support Staff 16 Posted by Ondina D.F. on 25 Aug, 2015 01:44 PM
See if this answer is of any use to you:
http://knowledge.robotlegs.org/discussions/problems/5818-viewmediat...
Support Staff 17 Posted by Ondina D.F. on 25 Aug, 2015 01:45 PM
Have you tried to add a simple view with a simple mediator already....?
A view with no states, no specified positions, etc.
18 Posted by kamcknig on 25 Aug, 2015 01:48 PM
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 Posted by kamcknig on 25 Aug, 2015 01:49 PM
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 :)
Support Staff 20 Posted by Ondina D.F. on 25 Aug, 2015 01:50 PM
Yeah, but make an effort and do add a simple view as I said:)
Support Staff 21 Posted by Ondina D.F. on 25 Aug, 2015 01:54 PM
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.
Support Staff 22 Posted by Ondina D.F. on 25 Aug, 2015 02:03 PM
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 Posted by kamcknig on 25 Aug, 2015 02:05 PM
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 Posted by kamcknig on 25 Aug, 2015 02:07 PM
Ah sorry, no, my structure as of now is
If I wrap Child1-4 in a VGroup it all breaks
Support Staff 25 Posted by Ondina D.F. on 25 Aug, 2015 02:11 PM
Ok, now try to add PointOfSaleView to the stage exactly like the DummyView.
26 Posted by kamcknig on 25 Aug, 2015 02:15 PM
Actually to be more accurate I would be wrapping Child3 and Child4 in a VGroup
27 Posted by kamcknig on 25 Aug, 2015 02:17 PM
OK If I add PointOfSaleView the same way as DummyView then it still all works (this is without the VGroup by the way).
Support Staff 28 Posted by Ondina D.F. on 25 Aug, 2015 02:20 PM
Now, add the PointOfSaleView to the VGroup (id="vGroup" for the sake of an example) instead of the MainView
vGroup.addElement( new PointOfSaleView());
29 Posted by kamcknig on 25 Aug, 2015 02:25 PM
After adding PointOfSaleView to MainView, add it to a vGroup within MainView? or just add it directly to VGroup first?
Support Staff 30 Posted by Ondina D.F. on 25 Aug, 2015 02:26 PM
directly to vgroup