title: ActionScript3 remove child error
body: <p>I recently have been converting an as2 fla to as3 (new to AS3) and have the entire thing working on export, but I am getting an error when I try to remove previously loaded swf's before a new swf is loaded</p>
  
  <pre><code>ArgumentError: Error #2025: The supplied DisplayObject
  must be a child of the caller.
  at flash.display::DisplayObjectContainer/removeChild()
  at MethodInfo-11()
  </code></pre>
  
  <p>I know the error relates to my removeChild code here: </p>
  
  <pre><code>`stage.addEventListener(MouseEvent.CLICK, removeSWF);
  function removeSWF (e:MouseEvent):void 
  {
  if(vBox.numChildren !=0){        
     // swfLoader.unloadAndStop();
      vBox.removeChild(swfLoader);// empty the movieClip memory
  }
  }`
  </code></pre>
  
  <p>However, I cannot seem to find a suitable rewrite for this code that will work and not have an error.  This code IS working, so I'm not sure if it would be worth my time to fix this error, or just leave it.  I've already messed with it for a couple days, so at this point it's just frustrating me that I cannot fix it.
  The stage mouse click listener is useful in this case because I have a back button not shown in this code that clears the loaded swf's before moving to another scene.
  Does anyone see a simple solution for this, or do you think it is unnecessary to pursue since the code does what I require?
  ENTIRE CODE: </p>
  
  <pre><code>function launchSWF(vBox, vFile):void    {
  var swfLoader:Loader = new Loader();
  var swfURL:URLRequest = new URLRequest(vFile);
  swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
  swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
  swfLoader.load(swfURL);
  
  function loadProdComplete(e:Event):void {
      trace("swf file loaded");   
      vBox.removeChild(preLoader);
      vBox.addChild(swfLoader);   
      currentSWF = MovieClip(swfLoader.content);
      currentSWF.gotoAndPlay(1);
      currentSWF.addEventListener(Event.ENTER_FRAME , checkLastFrame);
      swfLoader.x = 165;
      swfLoader.y = 15;
  
      function checkLastFrame(e:Event):void { 
          if (currentSWF.currentFrame == currentSWF.totalFrames) {
          currentSWF.stop();
          // trace("DONE");     
          }
      }      
  } 
  var preLoader:loader = new loader();
  preLoader.x = 450;
  preLoader.y = 280;
  vBox.addChild(preLoader);
  
          function onProgressHandler(event:ProgressEvent){
              var dataAmountLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
              //preLoader.bar.scaleX = dataAmountLoaded/100;
              preLoader.lpc.text= int(dataAmountLoaded)+"%";
              //trace(preLoader.bar.scaleX );
          }   
  //NEW ERRORS BUT WORKING
  stage.addEventListener(MouseEvent.CLICK, removeSWF);
  function removeSWF (e:MouseEvent):void 
  {
  if(vBox.numChildren !=0){        
     // swfLoader.unloadAndStop();
      vBox.removeChild(swfLoader);// empty the movieClip memory
  }
  }
  }
  var container:MovieClip = new MovieClip();
  var currentSWF:MovieClip = new MovieClip();
  
  fall_b.addEventListener(MouseEvent.CLICK, fall_bClick);
    function fall_bClick(e:MouseEvent):void {
    var swfFile:String = 'load/fall.swf';
    launchSWF(container, swfFile);
    addChild(container);
    }
  
  face_b.addEventListener(MouseEvent.CLICK, face_bClick);
    function face_bClick(e:MouseEvent):void {
    var swfFile:String = 'load/face.swf';
    launchSWF(container, swfFile);
    addChild(container);
    }
  
  rott_b.addEventListener(MouseEvent.CLICK, rott_bClick);
    function rott_bClick(e:MouseEvent):void {
    var swfFile:String = 'load/rottgut.swf';
    launchSWF(container, swfFile);
    addChild(container);
    }
  //MORE SWFS...
  </code></pre>
  
  <p>Any advice anyone has is appreciated</p>