How can I use the same mediator class(unchanged) for different view classes?
I have a contextview mediator class that is same for all my apps(for external communication) but every time I create a new app I need to change the view class name inside the mediator class
[Inject] public var view:NewAppMain;
I'd like to use this mediator class unchanged, is it possible? Maybe using interface or by extending?
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 stephenadams1 on 08 Mar, 2012 10:24 AM
I would create a parent mediator class, then subclass this in order to create a mediator for each view. This way all the main, repeatable work in handled by the parent. Then if one of your mediators later needs it's own specific piece of functionality, then you add that to the child mediator for that view.
Stephen
2 Posted by freqnc on 08 Mar, 2012 10:29 AM
ok but there are references to the view class inside the code, it has to be already in the parent...
3 Posted by freqnc on 08 Mar, 2012 12:37 PM
I tried it like this - the contextview class extends a class that is injected to the mediator - but got errors when trying to map the subclass...
4 Posted by Abel de Beer on 08 Mar, 2012 02:06 PM
Assuming you use RL1, I would recommend the following:
Have your main class implement an interface, say IContextView.
When you map the contextView to its mediator in the context, use the "injectViewAs" parameter:
mediatorMap.mapView(contextView, ContextViewMediator, IContextView);
Now you can inject the contextView in your mediator like this:
[Inject] public var view:IContextView;
What's nice about this approach is that you can use the custom methods you set up in your interface through the injected view property, but you're also able to use your Main app's DisplayObjectContainer functionality (e.g.
addChild();
) through the contextView property that is injected into the default Mediator, if necessary.5 Posted by freqnc on 08 Mar, 2012 03:09 PM
I have tried this also but I cannot access to the contextView stage that is crucial to my apps...
override public function onRegister():void
gives
1119: Access of possibly undefined property stage through a reference with static type net.unrealcasino.common.views:IContextView
and it seems that I cannot use even the DisplayObjectContainer functionality?
1061: Call to a possibly undefined method dispatchEvent through a reference with static type net.unrealcasino.common.views:IContextView
6 Posted by Stray on 08 Mar, 2012 04:18 PM
If you look, you'll see you own
> net.unrealcasino.common.views:IContextView
So if you make that interface extend IEventDispatcher then you'll be able to dispatch events, and if you add a getter for stage to that interface you'll be able to access the stage.
The other option is to use the contextView property rather than your view
eg:
contextView.stage.addEventListener...
Stray
7 Posted by freqnc on 09 Mar, 2012 08:05 AM
Of course contextView is available in the mediator!
Thanks guys, this is the solution I was trying to figure out!
Ondina D.F. closed this discussion on 13 Mar, 2012 01:08 PM.