I have some problem with views and mediators. I have view named Shop and his mediator.
I mapped it in my context: Code:
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?
Below pasted a piece of my code.
Context initialization: Code:
override public function startup():void
{
....
mediatorMap.mapView(Shop, ShopMediator);
...
mediatorMap.mapView(GameFace, GameFaceMediator);
...
}
Object of shop is create in GameFace:
Code:
public function initShop(aX:Array):void
{
shop = new Shop();
_aX = aX;
}
And was added to scene when player open shop in game:
Code:
public function openShop(tab:uint = 100):void
{
shop = new Shop();
addChild(shop);
shop.init(_aX);
shop.x = 396;
shop.y = 267;
}
Of course object of GameFace was added to display list. Someone know whats wrong is in my code?
If your application set-up is anything like mine, you may not actually be creating/activating the mediator. The
mediatorMapjust keeps a map of components to the mediators that they need.Try adding the code below to the constructors of both
ShopandGameFace:This should ensure that your mediator gets activated when the
ShopandGameFacehit the stage. The activator is found in the packagerobotlegs.utilities.lazy.If that doesn't work, you may need to call
mediatorMap.createMediator(shop)manually whenshophits the stage, but the built-in lazy option is preferable.