Extending view/mediator classes

kotharavi's Avatar


26 Aug, 2011 09:37 PM


My Problem: I have four different screens each showing different data, but the base layout is same for all. So, I have a base class which has the layout defined "BasePanel.as". Now all my panels extend from this class. Similarly I have a 'BaseMediator.as' class from which all the mediator classes extend.
Assuming that I have two more panels for now (PanelA, PanelB --> BasePanel similarly MediatorA, MediatorB --> BaseMediator)


//In this class I am injecting the base panel and a reference to app model (I expect the app model to be available to all extending panels). [Inject] public var panelView:BasePanel;

[Inject] public var applicationModel:AppModel;

So in my 'context' I have mapped the panel to mediator as below

mediatorMap.mapView(BasePanel, BaseMediator);
mediatorMap.mapView(PanelA, MediatorA, [ PanelA, BasePanel ]); //found this solution on the blog
mediatorMap.mapView(PanelB, MediatorB, [ PanelB, BasePanel ]);

And in my MediatorA.as

//In this class I do not have Inject annotation again here for 'panelA'

//function to update view 'private function updateDisplay(evt:UpdateEvent):void {

 (panelView as PanelA).dataGrid.dataProvider = evt.result;   //Is casting to a sub class allowed ?


My strange experience here is, I get a run-time error 'TypeError: Error #1006: value is not a function.'

But, if I have a trace statement before I actually update the dataProvider it works well.
sth like this 'trace(" Ref to DataGrid " + (panelView as PanelA).dataGrid)'

Question: Is my approach to inheritance is correct ? Am I allowed to up-cast the reference of base class to sub class and do some operations ? Why is that I don't see the type error 1006 when I don't have a trace statement printing the reference to DataGrid ?

If there is a better way to solve my problem, let me know.


  1. Support Staff 1 Posted by creynders on 28 Aug, 2011 12:55 PM

    creynders's Avatar

    I don't think it's necessary to map BasePanel to BaseMediator, unless if you want to mediate a BasePanel instance separately.
    The error you're receiving has nothing to do with RL I think. Could you post the entire stack trace?
    My guess is that the datagrid isn't initialized entirely before you try to assign its dataprovider. Because of the trace there's a small delay, which is enough to complete its initialization. But as I said that's just a guess.

  2. Ondina D.F. closed this discussion on 02 Nov, 2011 05:24 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