Problem with medaitor

patpas20's Avatar


24 Oct, 2012 08:48 AM

I have some problem with views and mediators. I have view named Shop and his mediator.

I mapped it in my context:
mediatorMap.mapView(Shop, ShopMediator);

Then I create object of Shop and add to stage just as user open shop in the game. The problem is that the mediator is not called at all in the application.

Anyone know what is the reason?

  1. Support Staff 1 Posted by Ondina D.F. on 24 Oct, 2012 09:00 AM

    Ondina D.F.'s Avatar


    Take a look at this:

    Please let us know whether it solved your problem or not.


  2. Support Staff 2 Posted by Ondina D.F. on 24 Oct, 2012 09:02 AM

    Ondina D.F.'s Avatar
  3. Support Staff 3 Posted by Ondina D.F. on 24 Oct, 2012 09:46 AM

    Ondina D.F.'s Avatar

    Is it a Flex or a pure as3 project?

    Could you post some code (or attach a simplified example) showing:

    -Context initialization in your main display object

    -Order of the mappings in your Context

    -Where and how you’re adding the view to the display list

    -What kind of a component is “Shop”. Is it by any chance a popup container?

    I think you’re adding the view to the display list before the mapping was made.

    In the case of Mediators the mappings have to occur before their Views hit the stage.
    The moment a View is added to the display list the MediatorMap creates a Mediator for that View, but only if they were already mapped.
    Exception from the rule: the main application container.

  4. 4 Posted by patpas20 on 24 Oct, 2012 08:52 PM

    patpas20's Avatar

    Thanks for replay but any sugestion don't help me. Below pasted a piece of my code.

    Context initialization:

    override public function startup():void
    mediatorMap.mapView(Shop, ShopMediator);
    mediatorMap.mapView(GameFace, GameFaceMediator);

    Object of shop is create in GameFace:

    public function initShop(aX:Array):void
            shop = new Shop();
            _aX = aX;

    And was added to scene when player open shop in game:

        public function openShop(tab:uint = 100):void
            shop = new Shop();
            shop.x = 396;
            shop.y = 267;

    Of course object of GameFace was added to display list.
    Someone know whats wrong is in my code?

  5. Support Staff 5 Posted by Ondina D.F. on 25 Oct, 2012 09:58 AM

    Ondina D.F.'s Avatar


    You didn’t answer my questions, and you didn’t post the code for context initialization in your main class. I can’t see what’s going on from the snippet you posted. I don’t know when is the view added and where. Is GameFace your main class? Also, I don’t know why you’re adding the view twice. [Edit] created the view twice

    I guess it’s a pure as3 project. I’ll attach a simple project to show you how you should proceed, and hopefully that will help you :)

    Here, just the code for the

    public class ContextView extends Sprite
            private var context:ApplicationContext;
            public function ContextView()
                stage.align = StageAlign.TOP;
                stage.scaleMode = StageScaleMode.NO_SCALE;
                context = new ApplicationContext(this);
                /////////////////////////////////////// [[[option 1]]]
                addEventListener(Event.ADDED_TO_STAGE, onViewAdded);
            private function onViewAdded(event:Event):void
                removeEventListener(Event.ADDED_TO_STAGE, onViewAdded);
                /////////////////////////////////////// [[[option 2]]]
                /*context = new ApplicationContext(this);
            public function createChildren():void
                var someView:SomeView = new SomeView();
                someView.x = 10;
                someView.y = 20;

    context = new ApplicationContext(this);

    Here, SomeView is added to the stage before the mappings in the context occurred, therefore its Mediator (SomeMediator) can’t be created

    context = new ApplicationContext(this);//first create the context
    createChildren(); //then add the view

    Inside the code that I’ve attached to this post there are 4 places where you can add SomeView, and I commented them like this:

    [[[option 1]]] ContextView constructor

    [[[option 2]]] ContextView on added to stage

    [[[option 3]]] ApplicationContext on ContextEvent.STARTUP_COMPLETE

    [[[option 4]]] ApplicationMediator onRegister()

    I used option 3: ApplicationContext. onStartUpComplete()

    It is important that SomeView gets added to the stage after mapping it to its mediator!!

    If that doesn’t help you either, you’ll have to attach an example reproducing the issues you’re having, and I’ll take a look at it.


  6. Ondina D.F. closed this discussion on 29 Oct, 2012 03:47 PM.

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