ViewMediator changes after windowresize

KBC's Avatar


05 Aug, 2014 11:06 AM


we might have found a bug. Everything is described here:
We think that it should not be a normal behaviour to change a existing mediator only because a parent changed.


  1. Support Staff 1 Posted by Ondina D.F. on 05 Aug, 2014 02:44 PM

    Ondina D.F.'s Avatar


    • Firstly, it's not a robotlegs bug. The mediator map provides mediator creation for mapped views landing on the stage.

    RobotLegs thinks that the whole view is added to the stage and a new mediator is assigned

    For a fact, the view is first removed from stage and then added to the stage again! That's what Adobe calls 'reparenting':

    "A view state can change the parent container of a component. Changing the parent container of a component is called reparenting the component."

    More details here:

    I don't recall exactly whether re-parenting after resizing was a Flex bug or not, but if it was a bug it seems that it hasn't been resolved. However, re-parenting of components happens under other circumstances as well: drag and drop, transition effects..

    • Secondly, Amy is absolutely right! Mediators shouldn't hold state. That's what Models are for. Maybe it's time to refactor your Mediators? :)

    • Anyway, a workaround could be this:

    You set the autoRemove of the mediator to false, in order to keep it alive when the view gets reparented. Of course, you'll have to remove the mediator manually, if need be.

    Then, you create a guard. For the sake of an example I created it inside of SomeMediator. You can use another class, if you wish.

    public function approve():Boolean
        if( view.needsMediator )
            return true;
            return false;

    Inside your view you create getters and setters for a needsMediator and set it to true.
    Then, you set the view.needsMediator = false within mediator's initialize().
    The first time SomeMediator is about to be created, view.needsMediator is true, so the guard will 'approve' the creation of the mediator.
    Next time, after reparenting the view, view.needsMediator will return false, thus the guard won't approve the creation of a new mediator for SomeView. The old mediator will react to events coming from SomeView or framework classes.

    needsMediator is a silly name. It's up to you how you name the flag, and whether it is a property of the view or of the mediator.

    You'll have to try this out with your settings to see if it works for you. I can't reproduce your use case on my end, thus I can't guarantee that my workaround will solve your problem.

    Let us know about your progress.


  2. Support Staff 2 Posted by Ondina D.F. on 01 Sep, 2014 12:30 PM

    Ondina D.F.'s Avatar

    I'm assuming you've resolved the issue, thus I'm going to close this discussion. Feel free to re-open it, if you want to respond or if you need more assistance with this.

  3. Ondina D.F. closed this discussion on 01 Sep, 2014 12:30 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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