How to remove a view in Stage?

yellow.as's Avatar

yellow.as

04 May, 2013 07:05 AM

add a view:

mediatorMap.map(Login).toMediator(LoginMediator);
contextView.view.addChild(new Login);

but,how to remove `Login` and release the `LoginMediator`?

  1. 1 Posted by yellow.as on 04 May, 2013 07:23 AM

    yellow.as's Avatar

    like the `Login panel`,when I was login,I don't need it after login,
    what's the right way to destroy the view `Login panel` ?
    I know Mediator has a function named `destroy()`,but how to destroy Mediator's view? just use `contextView.removeClild(someMediator.view)` ?

  2. Support Staff 2 Posted by Ondina D.F. on 04 May, 2013 09:23 AM

    Ondina D.F.'s Avatar

    what's the right way to destroy the view Login panel?

    The usual way to destroy a view is to let the parent of that view remove it from stage.

    In your case, let’s say that the parent view is MainView mapped to MainMediator.
    MainView has 2 methods, addLoginView() and removeLoginView().
    In addLoginView() you add LoginView to the stage. LoginMediator will be created automatically.

    MainMediator adds a listener for a context event, say LoginEvent.LOGIN_SUCCESSFUL, dispatched by a LoginService, and in its handler method it accesses MainView’s API, removeLoginView(), where the view itself removes its child from the stage. When LoginView gets removed from stage, its mediator, LoginMediator, will be removed as well.

    Does this answer your question?

  3. 3 Posted by yellow.as on 04 May, 2013 09:40 AM

    yellow.as's Avatar

    thank you Ondina D.F.

    I just write this in Mediator when the view need remove

    contextView.view.removeChild(view);
    this.view = null;
    this.destroy();
    

    I think this is the way with your suggestion

  4. Support Staff 4 Posted by Shaun Smith on 04 May, 2013 10:00 AM

    Shaun Smith's Avatar

    You should not call destroy() manually. It will be invoked automatically when the mediator is destroyed (which happens when its view leaves the stage). This should be all you need:

    view.parent.removeChild(view);
    

    You do not need to set the view reference to null either, because after the line above the mediator will be free for garbage collection (as will the view, provided there aren't other references to it).

  5. 5 Posted by yellow.as on 04 May, 2013 10:03 AM

    yellow.as's Avatar

    @Shaun Smith

    Got it,it's so simple,thank you.

  6. Support Staff 6 Posted by Shaun Smith on 04 May, 2013 10:17 AM

    Shaun Smith's Avatar

    My pleasure! I'm going to close this as resolved.

  7. Shaun Smith closed this discussion on 04 May, 2013 10:17 AM.

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