how prevent child context to be destroyed?

wayne's Avatar

wayne

07 Aug, 2014 03:21 AM

hello!
when the child module be removed from its parent, I don't want the child module context to be destroyed.
how prevent child context to be destroyed?

  1. Support Staff 1 Posted by Ondina D.F. on 07 Aug, 2014 01:35 PM

    Ondina D.F.'s Avatar

    Hello Wayne,

    As you know, a context is automatically destroyed when its contextView is removed from stage.

    StageSyncExtension:

    private function onRemovedFromStage(event:Event):void
    {
        _logger.debug("Context view has left the stage. Destroying context...");
        _contextView.removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
        _context.destroy();
    }
    

    You can use event.stopImmediatePropagation(); in the handler of Event.REMOVED_FROM_STAGE in your contextView (your module) to prevent the framework from listening for that event. The context won't be destroyed, but, I think that you'll run into problems if/when you want to add the module to the stage again.

    I'm not sure if there is a more elegant solution to this, that's why I've notified Shaun and creynders, in the hope they can give you additional solutions on how to detain a childContext.

    Can you tell us why do you need to keep the module's context alive when you remove the module?

    Ondina

  2. 2 Posted by wayne on 07 Aug, 2014 03:09 PM

    wayne's Avatar

    Thank you very much! Great!
    that's good way,I'm going to test it.
    Reason for keep the module's context alive is :
    i want to use the module as a singleton.
    I don't want to rebuild the module instance, when the module is added to displayl list again.Repeat an instance is created, a waste of system resources, but also the risk of leaking

  3. Support Staff 3 Posted by Ondina D.F. on 08 Aug, 2014 08:19 AM

    Ondina D.F.'s Avatar

    You're welcome, Wayne. Since you're content with this solution, I'll mark this discussion as resolved. You can re-open it, if need be.

  4. Ondina D.F. closed this discussion on 08 Aug, 2014 08:19 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