PDA

View Full Version : Preloader



xcrap
September 18th, 2003, 09:36 AM
Hi.

I have a movie in a single frame that have the following action script to random load external swf's.

I wonder how can i do to preload the swf's first



function virgem(){
movies = [1,2,3,4,5];
last = Math.floor(Math.random()*movies.length);
loadMovie("random_index_port/random" + movies[last] + ".swf","background");
}

function rnd(){
movies = [1,2,3,4,5];
choice = Math.floor(Math.random()*movies.length);
while(choice == last) {
choice = Math.floor(Math.random()*movies.length);
}
last = choice;
loadMovie("random_index_port/random" + movies[last] + ".swf","background");
}

a=1;
if (a==1) { virgem(); a=2; }

timer = setInterval(rnd,10000);
stop();


I've seen this code somewhere.. a preloader...



frame 1:
loadMovie("myMovie.swf","myTarget");

frame 2:
// nothing in here

frame 3:
actBytes = myTarget.getBytesLoaded() || 0;
totBytes = myTarget.getBytesTotal() || 100;
percent = Math.round(actBytes * 100 / totBytes);

if( totBytes - actBytes > 10){
// if you don't want a bar, delete the following line
bar._xscale = percent;
gotoAndPlay(2)
}

frame 4:
// ready, go


But i'm not using gotoandplay in my movie and he starts playing the swf right away, so won't the second preloader example do the same... help :)

eki
September 18th, 2003, 12:03 PM
Originally posted by xcrap


function virgem(){
movies = [1,2,3,4,5];
last = Math.floor(Math.random()*movies.length);
loadMovie("random_index_port/random" + movies[last] + ".swf","background");
}

function rnd(){
movies = [1,2,3,4,5];
choice = Math.floor(Math.random()*movies.length);
while(choice == last) {
choice = Math.floor(Math.random()*movies.length);
}
last = choice;
loadMovie("random_index_port/random" + movies[last] + ".swf","background");
background._visible = 0;
loadingID = setInterval("waitForLoad", 30);
}
function waitForLoad(){
if(background.getBytesLoaded()>40 && background.getBytesLoaded() >= background.getBytesTotal()){
background._visible = 1;
clearInterval(loadingID);
} else {
myTextField.text = background.getBytesLoaded()/1024 +"Kb of "+background.getBytesTotal()/1024;
}
}
a=1;
if (a==1) { virgem(); a=2; }

timer = setInterval(rnd,10000);

stop();

xcrap
September 18th, 2003, 03:24 PM
Thanks alot! :)