Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : Preloader For External Swf


sheedy
6/16/2004 11:40:21 PM
I have a main movie (not a movie clip), "main", that I want to load an external
SWF, "car", into. "Car" has it's own pre loader but I want "main" to wait until
"car" has fully loaded before continuing to the next point.
Can this be done? I have tried using the getBytesLoaded and getBytesTotal code
but can't seem to get it right... I am fairly new at this. I 'm not sure
exactly what it is that I have to "target" in order for the action to function
properly (the movie clip instance or the _level ??).
Can anyone help me?
kglad
6/17/2004 12:44:53 AM
to load car.swf into your main movie you need a target. either a movieclip
target or a _level target.

if you use a target movieclip your code would look something like:

_root.createEmptyMovieClip("targetMC",1); // creates the target movieclip
targetMC.loadMovie("car.swf"); // load your movie
preloadI=setInterval(preloadF,100); // start your preloader
function preloadF(){

if(targetMC.getBytesLoaded()>0&&targetMC.getBytesLoaded()>=targetMC.getBytesTota
l()){
clearInterval(preloadI);
// car.swf has completed loading. do whatever.
} else {
// your movie is loading do whatever.
}
}
sheedy
6/17/2004 2:50:17 AM
Thanks. I have managed to load the external SWF (which has it's own preloader)
into my target MC but its getting the main movie to wait until it has loaded
before it continues, that I am having problems with. So I dont need the
preloader stuff just the action that tells the main movie to wait until the
external file has loaded. Is that the

if(targetMC.getBytesLoaded()>0&&targetMC.getBytesLoaded()>=targetMC.getBytesTota
l())
code? I'm at work at the moment so I can't actually check it.
Branching
6/17/2004 7:23:44 AM
your 1st post=
I want "main" to wait until "car" has fully loaded before continuing
2nd post=
but its getting the main movie to wait until it has loaded before it continues

sheedy
6/17/2004 10:14:49 AM
Sorry. ... getting the main movie to wait until.. the external SWF... has
loaded before it continues.
So... I can load the external SWF no probs but I can't tell the main movie
what to do once the external SWF has loaded. I think i need to use the
onLoadComplete action but I don't know how to initiate it, in particular wether
or not to target the MC the SWF is being loaded into or the _level ????
kglad
6/17/2004 1:39:55 PM
yes, the code above allows you to do whatever while you're waiting for car.swf
to complete loading and to do whatever when it finishes loading. for example:

_root.createEmptyMovieClip("targetMC",1); // creates the target movieclip
targetMC.loadMovie("car.swf"); // load your movie
preloadI=setInterval(preloadF,100); // start your preloader
function preloadF(){

if(targetMC.getBytesLoaded()>0&&targetMC.getBytesLoaded()>=targetMC.getBytesTota
l()){
clearInterval(preloadI);
// car.swf has completed loading. if you want your main movie to play use:
this.play()?
} else {
// your movie is loading. if you want your main movie to wait use:
this.stop();
}
}
AddThis Social Bookmark Button