Skip to main content
Known Participant
July 13, 2006
Question

controlling external swf

  • July 13, 2006
  • 2 replies
  • 311 views
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...
This topic has been closed for replies.

2 replies

koomisanAuthor
Known Participant
July 13, 2006
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:
holder.moveBall();
but nothing happend
can you give me an example of how to use onLoadInit please?
thanks again for your help
Inspiring
July 13, 2006
Try this:
--
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc.moveBall();
};
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.addListener(mclListener);
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).

hth,
blemmo
Inspiring
July 13, 2006
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
ballMC.loadMovie("ball.swf");
you can access it with
ballMC.moveBall();

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).

hth,
blemmo