Prototipo de precarga de archivos externos. Indicandole un mc de destino, se encarga de crear en el mismo un holder para cargar la foto, una barra de precarga y un mc updater que se encarga del calculo. Esta es una versión reducida y personalizada del original, publicado en layer51
Actionscript:
MovieClip.prototype.preload = function(image, barWidth, imgWidth, imgHeight) {
var barWidth = barWidth == undefined ? 100 : barWidth;
var imgWidth = imgWidth == undefined ? 0 : imgWidth;
var imgHeight = imgHeight == undefined ? 0 : imgHeight;
this.createEmptyMovieClip("holder_mc", 0);
this.createEmptyMovieClip("updater_mc", 1);
this.createEmptyMovieClip("barra_mc", 2);
this.createEmptyMovieClip("filete_mc", 3);
this.barra_mc._xscale = 1;
with (this.barra_mc) {
beginFill(0x000000, 100);
lineTo(barWidth, 0);
lineTo(barWidth, 1);
lineTo(0, 1);
lineTo(0, 0);
}
with (this.filete_mc) {
//beginFill(0x000000, 100);
lineStyle(0, 0x0000);
lineTo(barWidth, 0);
lineTo(barWidth, 2);
lineTo(0, 2);
lineTo(0, 0);
}
if (imgWidth != 0) {
this.barra_mc._x = this.filete_mc._x=imgWidth/2-barWidth/2;
}
if (imgHeight != 0) {
this.filete_mc._y = imgHeight/2-this.filete_mc._height/2;
this.barra_mc._y = imgHeight/2-this.barra_mc._height/2+1;
}
this.holder_mc.loadMovie(image);
this.updater_mc.onEnterFrame = function() {
this.Loaded = this._parent.holder_mc.getBytesLoaded();
this.Total = this._parent.holder_mc.getBytesTotal();
this.Percent = Math.ceil((this.Loaded/this.Total)*100);
if (this.Loaded != this.Total || this.Total<=0) {
this.Percent = this.Total == 0 ? 0 : this.Percent;
this._parent.barra_mc._xscale = this.Percent;
trace(this.Percent+" %");
} else {
this._parent.barra_mc._xscale = this.Percent;
if (this.holder_mc._alpha>90) {
this.holder_mc._alpha = 100;
delete this.onEnterFrame;
} else {
this.holder_mc._alpha++;
}
this._parent.barra_mc.removeMovieClip();
this._parent.filete_mc.removeMovieClip();
this.removeMovieClip();
}
};
};
//Uso:
//image, barWidth, imgWidth, imgHeight
holder_mc.preload("http://www.bigwalls.de/Fotos/MontBlanc/Drus.jpg?"+random(99999), 60, 200, 200);
var barWidth = barWidth == undefined ? 100 : barWidth;
var imgWidth = imgWidth == undefined ? 0 : imgWidth;
var imgHeight = imgHeight == undefined ? 0 : imgHeight;
this.createEmptyMovieClip("holder_mc", 0);
this.createEmptyMovieClip("updater_mc", 1);
this.createEmptyMovieClip("barra_mc", 2);
this.createEmptyMovieClip("filete_mc", 3);
this.barra_mc._xscale = 1;
with (this.barra_mc) {
beginFill(0x000000, 100);
lineTo(barWidth, 0);
lineTo(barWidth, 1);
lineTo(0, 1);
lineTo(0, 0);
}
with (this.filete_mc) {
//beginFill(0x000000, 100);
lineStyle(0, 0x0000);
lineTo(barWidth, 0);
lineTo(barWidth, 2);
lineTo(0, 2);
lineTo(0, 0);
}
if (imgWidth != 0) {
this.barra_mc._x = this.filete_mc._x=imgWidth/2-barWidth/2;
}
if (imgHeight != 0) {
this.filete_mc._y = imgHeight/2-this.filete_mc._height/2;
this.barra_mc._y = imgHeight/2-this.barra_mc._height/2+1;
}
this.holder_mc.loadMovie(image);
this.updater_mc.onEnterFrame = function() {
this.Loaded = this._parent.holder_mc.getBytesLoaded();
this.Total = this._parent.holder_mc.getBytesTotal();
this.Percent = Math.ceil((this.Loaded/this.Total)*100);
if (this.Loaded != this.Total || this.Total<=0) {
this.Percent = this.Total == 0 ? 0 : this.Percent;
this._parent.barra_mc._xscale = this.Percent;
trace(this.Percent+" %");
} else {
this._parent.barra_mc._xscale = this.Percent;
if (this.holder_mc._alpha>90) {
this.holder_mc._alpha = 100;
delete this.onEnterFrame;
} else {
this.holder_mc._alpha++;
}
this._parent.barra_mc.removeMovieClip();
this._parent.filete_mc.removeMovieClip();
this.removeMovieClip();
}
};
};
//Uso:
//image, barWidth, imgWidth, imgHeight
holder_mc.preload("http://www.bigwalls.de/Fotos/MontBlanc/Drus.jpg?"+random(99999), 60, 200, 200);
