Skip navigation
akira32
Currently Being Moderated

load swf and get a SimpleButton in it

Jun 23, 2012 6:58 AM

Tags: #swf #simplebutton

I load a swf and want to get a button in the swf. But the button I get is NULL. I am sure the button's name is right and exists. Could somebody help me to solve this problem?

 

package
{
 import flash.display.MovieClip;
 
 import flash.net.URLRequest;
 import flash.display.Loader;
 import flash.events.Event;
 import flash.events.ProgressEvent;
 import flash.display.SimpleButton;
 
 import flash.display.LoaderInfo;
 
 public class MyClass1 extends MovieClip
 {
  public function MyClass1()
  {
   super();
   
   var swfLoader:Loader = new Loader();
   addChild(swfLoader);
   var bgURL:URLRequest = new URLRequest("secondFlash.swf");
   swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
   swfLoader.load(bgURL);
   
   var currentSWF:MovieClip = new MovieClip();
   
   function loadProdComplete(e:Event):void {
     
     var loaderInfo:LoaderInfo = e.target as LoaderInfo;
      var mv:MovieClip= MovieClip(loaderInfo.content);
 
    var btn1 = mv.getChildByName("btn1") as SimpleButton;
    trace("mv"+mv);
    trace("btn1="+btn1);
   }
  }
 }
}
 
 
Replies
  • Currently Being Moderated
    Jun 23, 2012 3:57 PM   in reply to akira32

    The code you show works fine for me.  How is btn1 created/named in the second swf file?  If you create it dynamically and do not assign a name property to it, it does not have the name you think it does.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points