title: Why do MovieClipLoader events not fire when loaded into an AS3 wrapper?
body: <p>While trying to answer this question: <a href="https://stackoverflow.com/questions/8064798/call-to-an-as2-function-from-the-as3-container">Call to an AS2 function from the AS3 container</a> I have come across a roadblock.  The setup is an AS3 SWF which loads an AS2 SWF, which in turn loads another AS2 SWF. Communication between the AS3 SWF and the parent AS2 SWF is achieved through localConnection.</p>
  
  <p><strong>child_as2.swf</strong> - This is a very simple timeline animation of a box moving across the screen with the following code on frame 1:</p>
  
  <pre><code>stop();
  function playMovie() {
      play();
  }
  </code></pre>
  
  <p><strong>parent_as2.swf</strong> - This is the intermediary AS2 container which loads in child_as2.swf.  The load is triggered by a LocalConnection call:</p>
  
  <pre><code>import mx.utils.Delegate;
  
  this._lockroot = true;
  
  var container:MovieClip = createEmptyMovieClip("container", 10);
  //mustn't cast this or the Delegate breaks
  var mcLoader = new MovieClipLoader();
  mcLoader._lockroot = true;
  mcLoader.onLoadInit = Delegate.create(this,onMCLoadInit);
  
  function onMCLoadInit() {
      trace("load init");
      container.playMovie();
  }
  
  //LocalConnection code
  var myLC:LocalConnection = new LocalConnection();
  
  myLC.loadChild = function(){
      mcLoader.loadClip("child_as2.swf", container);
      trace("loading");
  }
  
  myLC.connect("AVM");
  </code></pre>
  
  <p><strong>parent_as3.swf</strong> - This is the outer wrapper, written in AS3. It loads parent_as2.swf, and communicates with it via LocalConnection:</p>
  
  <pre><code>var myLC:LocalConnection = new LocalConnection();
  
  var loader:Loader = new Loader();
  loader.contentLoaderInfo.addEventListener(Event.INIT,onLoaded);
  loader.load(new URLRequest("parent_as2.swf"));
  addChild(loader);
  
  
  function onLoaded(event:Event):void {
      //setTimeout hack to circumvent #2000 Security context error
      setTimeout(function() {
          myLC.send("AVM", "loadChild");
      },1);
  }
  </code></pre>
  
  <p>The issue is that the <code>onMCLoadInit</code> function in parent_as2 is never called when it is loaded inside the AS3 wrapper, although the load does take place. The events also fail when using a listener object in place of Delegate.  The box from child_as2.swf is visible, but never starts moving.  However, if I run parent_as2.swf on it's own and start the load without the LocalConnection it works fine. It also wroks correctly when triggered from an external LocalConnection call.  Why does the AS3 wrapper prevent the MovieClipLoader's events from firing?</p>
  
  <h2>Update:</h2>
  
  <p>So accepting that no events can be fired from the MovieClipLoader in parent_as2.swf, I have modified the code to detect the loadInit state by a combination of polling <code>MovieClipLoader.getProgress()</code> and the existance of a function in child_as2.swf.  It's not pretty but it seems to work.  I would still much rather be able to offer a solution using events though.</p>
  
  <pre><code>var container:MovieClip = createEmptyMovieClip("container", 10);
  var mcLoader:MovieClipLoader = new MovieClipLoader();
  var loadStarted:Boolean;
  var checkingInt:Number;
  
  function checkProgress() {
      var progObj:Object = mcLoader.getProgress(container);
      if(progObj.bytesLoaded == progObj.bytesTotal &amp;&amp; loadStarted) {
          //load complete, wait for loadInit
          if(typeof(container.playMovie) == "function") {
              //loadInit
              clearInterval(checkingInt);
              container.playMovie();
          }
      }
      //ensures the first loop is ignored due to inaccuracy with reporting
      loadStarted = true;
  }
  
  //LocalConnection code
  var myLC:LocalConnection = new LocalConnection();
  
  myLC.loadChild = function() {
      loadStarted = false;
      mcLoader.loadClip("child_as2.swf", container);
      checkingInt = setInterval(checkProgress,5);
  }
  
  myLC.connect("AVM");
  </code></pre>