onRemove not being executed in my Mediator

Tadhg's Avatar

Tadhg

05 Aug, 2010 06:27 PM

Hey,

I have a mediator mapped to a view, nothing special. However when I remove my view the onRemove method is never executed.
My Sprite extends CasaSprite from the CasaLib and this is definitely the problem, if I use a normal Sprite everything seems fine. A problem I noticed in the CasaSprite is that it removes all the listeners on the instance of that CasaSprite before removing the instance from it's parent.

`public function destroy():void {

this._listenerManager.destroy();

this._isDestroyed = true;

if (this.parent != null)
this.parent.removeChild(this);

}`

Therefor the context would never get the REMOVED_FROM_STAGE event. However, even if I reorder these onRemove still doesn't execute.

The odd thing is if I set up a REMOVED_FROM_STAGE listener on the view in the mediator, that does execute, but the onRemove doesn't.

Any thoughts?

Cheers,

-T.

Here's my code in the mediator.

`override public function onRegister() : void {

view.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

}

private function onRemovedFromStage(event : Event) : void
{

trace("  [GameInstructionsMediator] onRemovedFromStage(event)"); // Traces fine

}

override public function onRemove() : void
{

trace("  [GameInstructionsMediator] onRemove()"); // Never traces

}`

  1. Support Staff 1 Posted by Shaun Smith on 05 Aug, 2010 06:36 PM

    Shaun Smith's Avatar

    That is weird! Does the view component, by any chance, end up back on stage just after being removed? The MediatorMap always waits one frame and checks view.stage is null before removing the mediator - this is to allow for "re-parenting".

  2. 2 Posted by ego on 13 Aug, 2010 03:39 PM

    ego's Avatar

    I just ran into the same issue and found this thread via google. shaun mentioned the "conflict". thes elines of the CasaSprite should open your eyes:

        override public function get stage():Stage {
            if (super.stage == null) {
                try {
                    return StageReference.getStage();
                } catch (e:Error) {}
            }
    
    
            return super.stage;
        }

    If you set the static reference to the stage in the StageReference class, the mediatorMap will never get a null value from any class extending CasaSprite

  3. Stray closed this discussion on 10 Feb, 2011 05:37 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