title: AS3 Who removed Child?
body: <p>I have hure legacy project. And sometimes one of my windows is removed from stage. I've created test project to simulate situation with chain of childs root.mc1.mc2.mc3.mc4</p>
  
  <p>mc4 is MovieClipWithEvents custom class</p>
  
  <p>After that I put line <code>removeChild(mc1);</code>
  In mc4 I also receive REMOVED_FROM_STAGE, but I can`t figure wich one of parent is removed.
  globalVisibleList method in trace shows:</p>
  
  <p>// mc4 added into mc3</p>
  
  <pre><code>[trace] onAddedToStage mc4 mc3 mc4 mc4              
  </code></pre>
  
  <p>// mc1 is removed from root, BUT event.target shows that mc4 is removed from mc3</p>
  
  <pre><code>[trace] onRemovedFromStage mc4 mc3 mc4 mc4      
  </code></pre>
  
  <p>//All parents still have their parents and are visible despite we know that mc1 is removed from root and received REMOVED_FROM_STAGE</p>
  
  <pre><code>[trace] [object MovieClipWithEvents2], mc4, true
  [trace] [object MovieClip], mc3, true
  [trace] [object MovieClip], mc2, true
  [trace] [object MovieClip], mc1, true
  [trace] [object Test_VisibleEvent2], root1, true
  [trace] [object Stage], null, true                  
  </code></pre>
  
  <p>//The next line <code>trace("*************\n" + mc4.globalVisibleList(mc4));</code>
  all is ok, mc1 is not child of root now</p>
  
  <pre><code>[trace] *************
  [trace] [object MovieClipWithEvents2], mc4, true
  [trace] [object MovieClip], mc3, true
  [trace] [object MovieClip], mc2, true
  [trace] [object MovieClip], mc1, true               
  </code></pre>
  
  <p>Test_VisibleEvent2 </p>
  
  <pre><code>package {
      import display.MovieClipWithEvents2;
  
      import flash.display.MovieClip;
      import flash.display.Sprite;
  
      public class Test_VisibleEvent2 extends Sprite {
          private var mc1:MovieClip;
          private var mc2:MovieClip;
          private var mc3:MovieClip;
          private var mc4:MovieClipWithEvents2;
          public function Test_VisibleEvent2() {
              mc1 = new MovieClip();
              mc2 = new MovieClip();
              mc3 = new MovieClip();
              mc4 = new MovieClipWithEvents2();
  
              mc1.name = "mc1";
              mc2.name = "mc2";
              mc3.name = "mc3";
              mc4.name = "mc4";
  
              addChild(mc1);
              mc1.addChild(mc2);
              mc2.addChild(mc3);
              mc3.addChild(mc4);
  
              removeChild(mc1);
              trace("*************\n" + mc4.globalVisibleList(mc4));
  
          }
      }
  }
  </code></pre>
  
  <p>MovieClipWithEvents2</p>
  
  <pre><code>package display {
      import flash.display.DisplayObject;
      import flash.display.MovieClip;
      import flash.events.Event;
  
      public class MovieClipWithEvents2 extends MovieClip {
          public function MovieClipWithEvents2() {
              addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
              addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
          }
  
          protected function onAddedToStage(event:Event):void {
              trace("onAddedToStage", name, parent.name, event.target.name, event.currentTarget.name);
          }
  
          protected function onRemovedFromStage(event:Event):void {
              trace("onRemovedFromStage", name, parent.name, event.target.name, event.currentTarget.name);
              trace(globalVisibleList(this));
          }
  
          public function globalVisibleList(displayObject:DisplayObject):String {
              var result:String = "";
              var checking:DisplayObject = displayObject;
              while(checking){
  
                  result += getNameAndVisible(checking);
  
                  if(checking.parent){
                      checking = checking.parent;
                  }else{
                      return result;
                  }
              }
              return result;// to make Idea happy
          }
  
          public function getNameAndVisible(displayObject:DisplayObject):String {
              return displayObject + ", " + displayObject.name + ", " + displayObject.visible + "\n";
          }
      }
  }
  </code></pre>
  
  <p>So I have two questions :</p>
  
  <ol>
  <li><p>Why mc4 receive REMOVED_FROM_STAGE, but all chain of parents is unbroken till Stage ?</p></li>
  <li><p>How to figure which parent is removed ?</p></li>
  </ol>