Skip navigation
mdnavaz
Currently Being Moderated

How can I control a button from one swf file to another swf file?

Apr 22, 2012 1:18 PM

Hi,

 

I have a main.swf file. From that file I am accessing the external.swf file which is an external file.

 

Now, how can I write code on my main.swf file for the button which is on my external.swf file?

 

Activities.MainPanel.close_btn.addEventListener(MouseEvent.CLICK, btnClickClose);

 

Activities.MainPanel.close_btn (This buttons is actually on external.swf file, but I want to write code on main.swf file to execute it on external.swf) how can I control one swf button on other swf file?

 

Thanks.

 
Replies
  • Currently Being Moderated
    Apr 22, 2012 3:38 PM   in reply to mdnavaz

    Is external.swf loaded into main.swf? If that's so then external.swf is a child of main.swf. Look in the online help for information on communicating between parent and child objects.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 22, 2012 9:53 PM   in reply to mdnavaz

    Depending on your setup you have a few options.

     

    1. local connection, not the best but works
    2. direct control - as Rob said, access the object based on its position in the display list of the Loader content (the Loader content is your external.swf)
    3. class control - if your button is a custom class (should be, if not then make it so), then create a new instance of the class
    4. static control - create a static reference to the element and call the reference
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 23, 2012 5:22 AM   in reply to mdnavaz

    Here's some example code that you should be able to adapt to your needs.

     

    // create a new loader object instance...

    var loader:Loader = new Loader();

    // make the download request...

    var request:URLRequest = new URLRequest("external.swf");

     

    // add a complete event listener to the loader

    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

     

    // start the actual loading process...

    loader.load(request);

     

    // create a new empty movieClip instance, you will put the loaded movie into this movieClip once its loaded

    var externalMovie:MovieClip;

     

     

    // this function is called when the download has finished and the file is ready to use...

    function completeHandler(event:Event):void {

       // set the contents of the loaded movie to the new empty movieClip...

               externalMovie = MovieClip(event.target.content);

       // add this new movie to the display list...

       addChild(externalMovie);

    }

     

    Now you can refer to the loaded movie with the instance name "externalMovie". So if, for instance, you want to address a button in the loaded movie, you could write something like this on the main timeline:

     

    externalMovie.addEventListener(MouseEvent.CLICK, btnClickClose);

     

    function btnClickClose(event:MouseEvent):void {

     

    }

     
    |
    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