Skip to main content
Inspiring
September 22, 2006
Answered

Preloader that changes external swfs every 5 seconds

  • September 22, 2006
  • 8 replies
  • 526 views
HI,

I've done an web banner in flash that loads an external swf and changes for another external swf after 5 seconds. The banner have a preloader, but the problem becomes when it loads the first time. As the swfs aren't cached in the browser's cache yet, the time for 5 seconds starts to count from the preloader, and when the external swf finally shows, only rest 1 second and it is changed to another. There is a way to "freeze" the time for each external swf until it totally loads?

The code that loads the swfs every 5 seconds (this code is placed into an action layer):

begin of code:

var intervalId:Number;
var count:Number = 0;
var maxCount:Number = 23;
var duration:Number = 0;
var banners:Array = new Array(
"abatrade.swf",
"bancobrasil.swf",
"caparao.swf",
"cedro.swf",
"cesama.swf",
"copasa.swf",
"damatta.swf",
"emtel.swf",
"engedrain.swf",
"extel.swf",
"feedback.swf",
"iti.swf",
"intermedium.swf",
"magnesita.swf",
"maquenge.swf",
"maxxdata.swf",
"orteng.swf",
"paiva.swf",
"paraibuna.swf",
"paraopeba.swf",
"sabesp.swf",
"serpro.swf",
"soll.swf",
"thawte.swf"
);

function executeCallback(param:String) {
var duration:Number = 5000;
loadMovie(banners[count],loadmovie_mc);
loadmovie_mc._x=0;
loadmovie_mc._y=0;

clearInterval(intervalId);
if(count < maxCount) {
count++ ;
intervalId = setInterval(this, "executeCallback", duration, banners[count]);
}
else {
count=0;
intervalId = setInterval(this, "executeCallback", duration, banners[count]);
}
}

if(intervalId != null) {
clearInterval(intervalId);
}

intervalId = setInterval(this, "executeCallback", duration, banners[count]);

//end of code
----------------------------------------

And the code for the preloader (this code I place into the movieclip that loads the external swfs):

//begin of code:

onClipEvent(enterFrame) {
var gtT:Number = this.getBytesTotal();
var gtL:Number = this.getBytesLoaded();
var gtP:Number = int((gtL/gtT)*100);
if ( gtT > gtL ) {
this._alpha = 0;
_root.loader._alpha = 100;
_root.loader.bar._width = gtP;
clearInterval(intervalId);
} else {
this._alpha = 100;
_root.loader._alpha = 0;
intervalId = setInterval(this, "executeCallback", duration, banners[count]);
delete onEnterFrame;
}
}

//end of code

Note that I tryed to freeze the time using a clearInterval in the second code, but it simply don't works...

Any Ideas? Thanks

Edson
This topic has been closed for replies.
Correct answer Edson_Correa
Below is the correct code that kglad send me. Thanks so much!

8 replies

kglad
Community Expert
Community Expert
September 28, 2006
you're welcome.
Inspiring
September 27, 2006
http://www.maxxdata.com.br/banners.zip

Open the fla and preview the file with bandwidth preview ( Crtl+Enter twice ). You will note that the third banner (caparao.swf) start to loads but it don't shows at all because the loading for a slow internet (56K) takes more than 5 seconds. So the loader skip to the next banner. Is there a way to "freeze" the time for the preloader (to give it enough time to the banner load completely, even in slow connections) and count the 5 seconds only to the banner itself?

Thanks.
kglad
Community Expert
Community Expert
September 27, 2006
here's your corrected fla:

www.gladstien.com/new/LOADALL_preloader_test.fla
Edson_CorreaAuthorCorrect answer
Inspiring
September 28, 2006
Below is the correct code that kglad send me. Thanks so much!

kglad
Community Expert
Community Expert
September 26, 2006
post a link to your fla.
kglad
Community Expert
Community Expert
September 26, 2006
what do you mean by ".. the time continues to count..."?

the code i gave has not coding for a display. it simply loads a swf, displays it for 5 seconds and then loads the next. when it reaches the last swf, it restarts with the first swf.
Inspiring
September 26, 2006
Now I understood! The code that you sent were to replace by the existing code. I tried, but nevertheless did not work... The code that I already had is working perfectly to change banners every 5 seconds. What I tried to do is to put a preloader that exhibited a progression bar before the exhibition of each banner and that this loading did not count the 5 seconds of banner exhibition. The code that I wrote, it exhibits the bar, however he counts the 5 seconds of banner exhibition from preloader. That is that I do not want. I want the 5 seconds be just counted from banner exhibition. Is that possible? Thanks.
Inspiring
September 25, 2006
Yes. The banners are defined throught the array within the variable "banners". The swf loads all banners, even with the script that you send me attached in the final of the script. But the time continues to count in the preloader and so the banners are showed for very few moments, after the preloads and pass to another banner...
kglad
Community Expert
Community Expert
September 25, 2006
did you define banners?
Inspiring
September 25, 2006
Doesn't works! Any ideas?
kglad
Community Expert
Community Expert
September 22, 2006
try: