Access to properties of view and model by mediator
Hello! I'm trying to learn Robotlegs by reading this
http://www.developria.com/2010/06/an-introduction-to-robotlegs-a-1....
, everything had perfect sense but I stuck. I cannot get access to
properties of view and model from mediator. It needs to be
something silly, but I can't see what I could omitted. If somebody
would be so kind to help... I will describe steps I did.
In my Context I wired elements that way:
injector.mapSingleton(CModel);
mediatorMap.mapView(MenuView, MenuMediator);
In my Mediator I injected both - my View and Model:
[Inject] public var view:MenuView; [Inject] public var model:CModel;
I can listen for events from views, and it works, also passing variables by using custom events to mediator also works. But in the above article there is that part in the mediator:
override public function onRegister():void {
view.items = authorModel.list; }
I setup setter in view, and getter in model, but if I try to do something like this, I'm always getting "Error: Access of undefined property" error... I cannot access any property and method of both - view and model. What more do I need to do?
Regards!
Comments are currently closed for this discussion. You can start a new one.
2 Posted by krasimir on 04 May, 2012 09:29 PM
Hello,
it is a little bit difficult for me to say the exact reason of problem, but are you sure that you are getting this error from the onRegister method. Can you please put a trace statement before view.items = authorModel.list;. If the trace appear then will be helpful to trace(view) and trace(authorModel) to see which of those is undefined.
3 Posted by Luken on 04 May, 2012 09:35 PM
This is not runtime error, this is compiler error. I cannot trace both of them because when I put "view.items" in trace i won't compile. I'm using FlashDevelop. It's funny, because it's hinting me that methods lol .
4 Posted by krasimir on 04 May, 2012 09:41 PM
My opinion is that your view is ok. I mean that the onRegister method is called when your view is added to the stage. So basically the variable view should be ok. What about the setter .items. What's in that method?
From the code above: in onRegister you typed "authorModel" but in your injection you have just "model". Isn't it possible to have a typo mistake here.
5 Posted by neil on 04 May, 2012 09:42 PM
Hey Luken
If it is a compiler error, than its not an error with how you are wiring up RL.
The only way I can comment is to see the Mediator and the view code.
If the code is ok, then it may well be your IDE, I'm not familiar with FD, but can you clear the project?
6 Posted by Luken on 04 May, 2012 10:27 PM
This is very strange, when I 'm just copying example, everything works. I didn't do everything the same, just tried to copy concepts, but it seems that I doesn't understand something, and made somewhere a mistake...
This is mediator:
package controller
{
}
This is view:
package view
{
}
I'm sure now that I'm just doing something wrong, but what it is? :/
7 Posted by Luken on 04 May, 2012 11:35 PM
Ok, I nailed it! When I changed a name of the model and view in mediator, it compiles. I investigated where else I was using word "view" and guess what - in the package structure. I don't know how, but when I changed it to "views" I can now using word "view" as a name of injected object again. That is one nasty trap >_< .
Thanks for your interest anyway :) .
Support Staff 8 Posted by Ondina D.F. on 05 May, 2012 06:39 AM
Hi Luken,
The issue you were having falls into the category of "naming conflicts”.
Take a look at the Common Problems
Error: Call to a possibly undefined method X: Definition name is the same as an imported package name.
If you'd google “naming conflicts”, or “naming conventions” you’d find lots of articles on the subject.
From Adobe:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/00000475.html
http://help.adobe.com/en_US/as3/learn/WS5b3ccc516d4fbf351e63e3d118a...
I know, lots of links, but hopefully useful in a way or another;)
Ondina
9 Posted by Luken on 05 May, 2012 08:46 AM
Thanks, that was just project for testing RobotLegs and I didn't care about package structure too much, also didn't know the consequences. Good to know now, thanks for the links :) .
Support Staff 10 Posted by Ondina D.F. on 05 May, 2012 01:20 PM
Hey, no problem:)
Ondina D.F. closed this discussion on 05 May, 2012 01:20 PM.
neil re-opened this discussion on 05 May, 2012 01:49 PM
11 Posted by neil on 05 May, 2012 01:49 PM
Ach that old one. I've lost days to that in the past.
well spotted.
Ondina D.F. closed this discussion on 29 Jun, 2012 09:08 AM.