title: AS3: Access function in external class located in external swf
body: <p>I am trying to access a function in a loaded swf that has external class..
  I would like to avoid having to put the function on my "Main" Doc class in the external swf
  and instead access the function directly from the class</p>
  
  <p>This is what ive tried so far and it's a no dice:</p>
  
  <pre><code> private function startLoad(){
          var loader:Loader = new Loader();
          var req:URLRequest = new URLRequest("one.swf");
          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
          loader.load(req);
  
      }
   private function onLoadComplete(e:Event):void{
          var ClassDefinition:Class = e.target.applicationDomain.getDefinition("com.view.Creative") as Class;
          var butn:MovieClip = new ClassDefinition(0,0);////0,0 is x and y cordinates I have in the "com.view.Creative" class
  
          this.addChild(butn);
          butn.setVar("one");////"setVar" is the function in my external swf with the class "com.view.Creative"
      }
  </code></pre>
  
  <p>This is the function in com.view.Creative.as</p>
  
  <pre><code>  public var storedVar:String
  
    public function setVar(str:String):void{
                 this.storedVar = str;
                 trace(storedVar)
      }
  </code></pre>
  
  <p>//Returns "ReferenceError: Error #1069: Property setVar not found on com.view.Creative and there is no default value."</p>
  
  <p>This is the other approach I took with no success</p>
  
  <pre><code>  private function startLoad(){
          var appDomain:ApplicationDomain = new ApplicationDomain();
          var context:LoaderContext = new LoaderContext(false, appDomain);
          var loader:Loader = new Loader();
          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); 
          loader.load(new URLRequest("one.swf"), context);
  
  
      }
  
    private function completeHandler(event:Event):void { 
          var myGreet:Class = ApplicationDomain.currentDomain.getDefinition("com.view.Creative") as Class;                
          var app : MovieClip = new myGreet(0,0)
          addChild(app);
          app.setVar("one");////set var is the function in my external swf with the class "com.view.Creative" I am trying to access
          //event.target.content.setVar("one");///this works if I am placing my "setVar" function on my "Main" Doc Class which I am trying to avoid///
  
      }
  </code></pre>
  
  <p>This is the function in com.view.Creative.as</p>
  
  <pre><code>   public var storedVar:String
  
     public function setVar(str:String):void{
                 this.storedVar = str;
                 trace(storedVar)
      }
  </code></pre>
  
  <p>//Returns "ReferenceError: Error #1069: Property setVar not found on com.view.Creative and there is no default value.
      at com.util::ClickArea/completeHandler()"</p>
  
  <p>There's gotta be a solution for this.....Thanks in advanced!</p>