3 Replies Latest reply on Jul 13, 2006 10:06 AM by blemmo

    controlling external swf

    koomisan Level 1
      hello, does anybody know if there is a way to control external swf files?
      if i load a file into a new one, is it possible to call a function that exists in the loaded file from the loading file?
      for example if i have a function that moves a ball in one swf, and i load that swf into a new page (with loadMovie), how do i call the moveBall function from there?
      is it at all possible?
      thanks to anyone who helps...
        • 1. Re: controlling external swf
          blemmo Level 1
          Yes, the loaded movie is accessible via the name of the movieclip it gets loaded into. E.g., if you have an MC called 'ballMC', and load the second movie with
          you can access it with

          But the movie has to be completely loaded, so you should make sure it finished loading before calling it's methods. Also, code in the frame of the loader movie will execute before the code in the loaded movie. E.g., if frame 1 of the ball movie says
          this.foo = "bar";
          the variable will only be set after all code in the frame of the loader movie is executed, so you can't use 'foo' in that frame.
          To make sure the movie is loaded, use preloading code or the MovieClipLoader class, which provides events that signal when the movie is loaded (onLoadInit).

          • 2. Re: controlling external swf
            koomisan Level 1
            thanks for the help,
            i did a preloader for the external swf, and when the file has finished loading, i tried to run the function, but it didn't work.
            the loaded swf is called "ball.swf", inside it there is a function called moveBall().
            i loaded ball.swf into a new mc (called holder), and once it finished loaded i wrote:
            but nothing happend
            can you give me an example of how to use onLoadInit please?
            thanks again for your help
            • 3. Re: controlling external swf
              blemmo Level 1
              Try this:
              var mclListener:Object = new Object();
              mclListener.onLoadInit = function(target_mc:MovieClip) {
              var mcl:MovieClipLoader = new MovieClipLoader();
              mcl.loadClip("ball.swf", holder);
              It's a bit different from what I wrote before, because the onLoadInit event gets the MC as a parameter, so you can use this instead of the instance name 'holder'. Outside the event, you can use the instance name like described above (always assuming the clip is loaded and initialised).