title: Access a function inside a loaded .swf file?
body: <p>Is there a way to call a function inside a loaded SWF file?</p>
  
  <p>Basically, I have a .swf file (A) that loads another .swf file (B)...I would just like to treat B as if it was any other instance added to my class .swf "A"...</p>
  
  <hr>
  
  <p>Have to recast "Loader" with the name of your .swf file class:</p>
  
  <p>Loaded .swf class:</p>
  
  <pre><code>package src {
  import flash.display.MovieClip;
  
  public class LoadedSWF extends MovieClip     {
      public function LoadedSWF() {
      }
  
      public function helloWorld():void
      {
          trace("hello world from loaded swf!");
      }
  }
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>package src {
  import flash.display.Loader;
  import flash.net.URLRequest;
  import flash.display.MovieClip;
  import flash.events.Event;
  
  public class Main extends MovieClip {
  
      private var loader:Loader;
  
      public function Main() {
          loadSWF("LoadedSWF.swf")
      }
  
      private function loadSWF(url:String):void {
          var urlRequest:URLRequest = new URLRequest(url);
          loader = new Loader();
          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded, false, 0, true);
          loader.load(urlRequest);
          addChild(loader);
  
      }
  
      private function onLoaded(e:Event):void {
          var target:LoadedSWF = e.currentTarget.loader.content as LoadedSWF;
          trace(target);
          target.helloWorld();
  
          addChild(target);
      }
  }
  </code></pre>
  
  <p>}</p>