PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: Arno on July 23, 2009, 07:25:15



Title: how does removeMediator works?
Post by: Arno on July 23, 2009, 07:25:15
I have different view components with there own mediator. I'm stuck at the point that I remove a view. I have a couple of questions about this:

1) do you remove the viewcomponent or the mediator first?

2) Can you just remove the mediator of do you also have to remove eventlisteners before you remove it? Because I tried to remove a viewcomponent and then the mediator. After that I get a error from the mediator on a addeventlistener. What is strange because if i check with facade.hasMediator he returns false for that mediator

3) I red somewhere about a destroy() function where do I put it and how does it look like? Or beter is there an example? I coundn't find one



Title: Re: how does removeMediator works?
Post by: Jason MacDonald on July 23, 2009, 08:00:16
Remove the mediator first, then in the mediators onRemove() function remove the view component.

example
:
override public function onRemove():void {
    viewComponent.parent.removeChild(viewComponent);
    // OR send a note to the parent objects mediator to remove
    sendNotification(REMOVE_CHILD, viewComponent);
}

You can also remove any relevant event listeners there as well.


Title: Re: how does removeMediator works?
Post by: Arno on July 24, 2009, 12:37:32
thank you very much. It is working!