Answered
Preloader that changes external swfs every 5 seconds
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
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