title: TypeError: Error #1006: addChild is not a function
body: <p>I'm trying to embed a "pre-made" flash actionscript 3 gallery into my own flash animation. Both animations work in good ways independently. But once I insert the photo gallery into my own project I am getting an error of;</p>
  
  <pre><code>TypeError: Error #1006: addChild is not a function.
  at project_fla::galeri_6/onCompleteXmlLoad()
  at flash.events::EventDispatcher/dispatchEventFunction()
  at flash.events::EventDispatcher/dispatchEvent()
  at flash.net::URLLoader/onComplete()
  </code></pre>
  
  <p>My flash button code which leads to gallery is;</p>
  
  <pre><code>stop();
  
  galeri_btn.addEventListener(MouseEvent.CLICK, galeri);
  
  function galeri(event:MouseEvent):void
  {
      gotoAndStop(3);
  }
  </code></pre>
  
  <p>And lastly, the flash gallery code is; </p>
  
  <pre><code>import flash.net.URLLoader;
  import flash.net.URLRequest;
  import flash.events.Event;
  import flash.display.MovieClip;
  import flash.display.Loader;
  import flash.events.MouseEvent;
  import flash.geom.Rectangle;
  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.TextFormat;
  
  
  var xmlLoader:URLLoader = new URLLoader(new URLRequest("photo_gallery.xml"));
  
  xmlLoader.addEventListener(Event.COMPLETE, onCompleteXmlLoad);
  
  var xmlFile:XML;
  
  
  var xcoord:int = 10;
  
  var gal:gallery = new gallery();
  gal.x = 10;
  gal.y = 10;
  addChild(gal);
  
  var thumbsContainer:Sprite = new Sprite();
  thumbsContainer.x = 10;
  thumbsContainer.y = 320;
  addChild(thumbsContainer);
  
  
  var txtTitle:TextField = new TextField();
  txtTitle.x = 15;
  txtTitle.y = 15;
  var format:TextFormat = new TextFormat();
  format.bold = true;
  format.color = 0xFFFFFF;
  format.size = "20";
  format.font = "Arial";
  txtTitle.defaultTextFormat = format;
  addChild(txtTitle);
  
  var txtDesc:TextField = new TextField();
  txtDesc.x = 15;
  txtDesc.y = 40;
  var format1:TextFormat = new TextFormat();
  format1.color = 0x000000;
  format.font = "Calibri";
  format.size = 12;
  txtDesc.defaultTextFormat = format1;
  addChild(txtDesc);
  
  function onCompleteXmlLoad(e:Event):void{
  
      xmlFile = new XML(xmlLoader.data);      
  
      var len:int = xmlFile.photo.length();
  
      txtTitle.text = xmlFile.photo.name[0];
      txtDesc.text = xmlFile.photo.desc[0];
  
      for(var i:int = 0;i&lt;len;i++){
          var t:thumbs = new thumbs();
          t.x = xcoord;
          t.y = 10;
          t.buttonMode = true;        
          t.name = (i+1).toString();              
          thumbsContainer.addChild(t);
  
          t.addEventListener(MouseEvent.MOUSE_OVER, onMouseover);
          t.addEventListener(MouseEvent.MOUSE_OUT, onMouseout);
          t.addEventListener(MouseEvent.CLICK, onMouseClick);
  
          var tloader:Loader = new Loader();
          tloader.load(new URLRequest("thumbs/" + (i+1) + ".jpg"));
          t.addChild(tloader);        
  
          xcoord += t.width + 10;
      }
  
      var loader:Loader = new Loader();
      loader.load(new URLRequest("img/1.jpg"));
      gal.addChild(loader);
  
  
      scroller.source = thumbsContainer;
      scroller.setSize(550,110);
  
  }
  
  function onMouseover(e:MouseEvent):void{
  
      e.currentTarget.alpha = 0.5;
  
  }
  
  function onMouseout(e:MouseEvent):void{
  
      e.currentTarget.alpha = 1.0;
  
  }
  
  
  function onMouseClick(e:MouseEvent):void{
  
      var loader:Loader = new Loader();
      loader.load(new URLRequest("img/" + e.currentTarget.name + ".jpg"));    
      gal.addChild(loader);       
  
      txtTitle.text = xmlFile.photo.name[int(e.currentTarget.name) - 1];
      txtDesc.text = xmlFile.photo.desc[int(e.currentTarget.name) - 1];
  
  }
  </code></pre>
  
  <p>Any help is appreciated. </p>