Using child mediators and injectviewas

bill's Avatar

bill

12 Sep, 2011 04:51 PM

Hey all,

I'm trying map a skinnablecomponent as a child mediator within a mediator mapped by the applicationcontext and am having a problem with onRegister() being fired twice for the child mediator.

It looks something like this:

`public class MainMediator extends Mediator{

var subView:MySkinnableComponent;

...

override public function onRegister():void{

subView = new MySkinnableComponent();

mediatorMap.mapView( subView, SubViewMediator, MySkinnableComponent );

}`

The problem is that onRegister() in SubViewMediator is getting fired twice even though it is only fired once in MainMediator. Am I implementing something wrong?

Thx,
WL

  1. 1 Posted by bill on 12 Sep, 2011 04:58 PM

    bill's Avatar

    On further research I've found that the 2nd onRegister() seems associated with the view being added to stage. In other words, if I don't add subView to stage I only see its mediator's onRegister() fired once. However, when added to stage using mainView.addElement( subView ), onRegister() is fired twice regardless of whether addElement() is before or after mapView().

  2. 2 Posted by bill on 12 Sep, 2011 09:16 PM

    bill's Avatar

    OK, I should've completed my research before posting this.

    It appears the problem is that I have 2 instances of my skinnablecomponent and even though I'm only declaring one mediator, it invokes onRegister() for each component instantiation. New code:

    public class MainMediator extends Mediator{

    var subView1:MySkinnableComponent;
    var subView2:MySkinnableComponent;

    ...

    override public function onRegister():void{

    subView1 = new MySkinnableComponent();
    subView2 = new MySkinnableComponent();

    mediatorMap.mapView( subView1, SubViewMediator, MySkinnableComponent );

    }`

    If I don't instantiate subView2, I only get one onRegister() event. So, is the answer here to use an interface vs. class as the injectviewas param?

    WL

  3. bill closed this discussion on 12 Oct, 2011 10:31 PM.

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