Access to properties of view and model by mediator

Luken's Avatar


04 May, 2012 09:18 PM

Hello! I'm trying to learn Robotlegs by reading this , 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:

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?


  1. 1 Posted by krasimir on 04 May, 2012 09:29 PM

    krasimir's Avatar


    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.

  2. 2 Posted by Luken on 04 May, 2012 09:35 PM

    Luken's Avatar

    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 .

  3. 3 Posted by krasimir on 04 May, 2012 09:41 PM

    krasimir's Avatar

    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.

  4. 4 Posted by neil on 04 May, 2012 09:42 PM

    neil's Avatar

    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?

  5. 5 Posted by Luken on 04 May, 2012 10:27 PM

    Luken's Avatar

    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

    import org.robotlegs.mvcs.Mediator;
    import view.MenuView;
    import view.MenuEvent;
    import model.CModel;
    public class MenuMediator extends Mediator 
        [Inject] public var view:MenuView;
        [Inject] public var model:CModel;
        override public function onRegister() : void {
            trace(view.message); // makes compiler error
            addViewListener(MenuEvent.CLICKED, handleMessage)
        private function handleMessage(e:MenuEvent) : void {


    This is view:

    package view

    import flash.display.Shape;
    import flash.display.Sprite;
    import view.MenuEvent;
    public class MenuView extends Sprite 
        private var myShape:Shape;
        private var mySprite:Sprite;
        private var _message:String;
        public function MenuView() 
            myShape = new Shape();
  , 0, 100, 100);
            mySprite = new Sprite();
            mySprite.addEventListener(MouseEvent.CLICK, fclick);
        private function fclick(e:MouseEvent) : void {
            dispatchEvent(new MenuEvent(MenuEvent.CLICKED,_message));
        public function set message(w:String) : void {
            _message = w;
        public function get message() : String {
            return _message;


    I'm sure now that I'm just doing something wrong, but what it is? :/

  6. 6 Posted by Luken on 04 May, 2012 11:35 PM

    Luken's Avatar

    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 :) .

  7. Support Staff 7 Posted by Ondina D.F. on 05 May, 2012 06:39 AM

    Ondina D.F.'s Avatar

    Hi Luken,

    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.

    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:

    I know, lots of links, but hopefully useful in a way or another;)

  8. 8 Posted by Luken on 05 May, 2012 08:46 AM

    Luken's Avatar

    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 :) .

  9. Support Staff 9 Posted by Ondina D.F. on 05 May, 2012 01:20 PM

    Ondina D.F.'s Avatar

    Hey, no problem:)

  10. Ondina D.F. closed this discussion on 05 May, 2012 01:20 PM.

  11. neil re-opened this discussion on 05 May, 2012 01:49 PM

  12. 10 Posted by neil on 05 May, 2012 01:49 PM

    neil's Avatar

    Ach that old one. I've lost days to that in the past.
    well spotted.

  13. Ondina D.F. closed this discussion on 29 Jun, 2012 09:08 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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