1 Reply Latest reply on Sep 26, 2012 1:42 PM by cpDev

    Resizing application causes createContentPane to dispatch second Event.REMOVED_FROM_STAGE

    cpDev

      My application relies heavily on the addedToStage and removedFromStage events. Yesterday, I hit a rather obscure edge case with these events, described here by an Adobe engineer:

       

      http://blogs.adobe.com/pmartin/2010/03/use_of_stage_ev.html

       

      I used the workaround described in the article where I create a contentPane in createChildren(). However, I find that despite this, when I resize my application window, the same Container throws a removedFromStage event from Container::createContentPane(). The code for that method checks for the existence of a contentPane, so I'm not sure why this is happening. I know that my contentPane is being created because I see the contentPane property change after the createContentPane() call.I'm attaching the code for that call below.

       

       

      /**
           *  @private
           */
          mx_internal function createContentPane():void
          {
              if (contentPane)
                  return;
      
              creatingContentPane = true;
      
              // Reparent the children.  Get the number before we create contentPane
              // because that changes logic of how many children we have
              var n:int = numChildren;
      
              var newPane:Sprite = new FlexSprite();
              newPane.name = "contentPane";
      
              // Place content pane above border and background image but below
              // all other chrome.
              var childIndex:int;
              if (border)
              {
                  childIndex = rawChildren.getChildIndex(DisplayObject(border)) + 1;
                  if (border is IRectangularBorder && IRectangularBorder(border).hasBackgroundImage)
                      childIndex++;
              }
              else
              {
                  childIndex = 0;
              }
              rawChildren.addChildAt(newPane, childIndex);
      
              for (var i:int = 0; i < n; i++)
              {
                  // use super because contentPane now exists and messes up getChildAt();
                  var child:IUIComponent =
                      IUIComponent(super.getChildAt(_firstChildIndex));
                  newPane.addChild(DisplayObject(child));
                  child.parentChanged(newPane);
                  _numChildren--; // required
              }
      
              contentPane = newPane;
      
              creatingContentPane = false
      
              // UIComponent sets $visible to false. If we don't make it true here,
              // nothing shows up. Making this true should be harmless, as the
              // container itself should be false, and so should all its children.
              contentPane.visible = true;
          }