Cargar imagenes externas en flash

Por lo que he podido comprobar, existen diversas formas de cargar imágenes externas. Todo depende de cuáles sean nuestros propósitos. A continuación, presento algunas de ellas, por supuesto, indicando el autor.

En este aporte podemos encontrar varias formas de hacerlo, aumentando la dificultad para alcanzar un efecto más dinámico.

Basico: Carga la imagen en un clip vacío a partir de unas coordenadas.

this.createEmptyMovieClip(“cargador”,1)
this.cargador._x=0
this.cargador._y=0
this.cargador.loadMovie(“../img/robot_flasxl.jpg”)

Intermedio: Igual que antes pero añadiendo una precarga.

this.createEmptyMovieClip(“cargador”, 1);
this.createTextField(“porcentaje”, 2, 0, 0, “200″, “16″);
this.cargador._x = 0;
this.cargador._y = 0;
this.cargador.loadMovie(“../img/robot_flasxl.jpg”);
//
this.onEnterFrame = function() {
this.cargador.percent = (this.cargador.getBytesLoaded()/this.cargador.getBytesTotal())*100;
if (!isNan(this.cargador.percent)) {
this.porcentaje.text = Math.round(this.cargador.percent)+” %”;
}
if (this.cargador.percent == 100) {
delete this.onEnterFrame;
}
};

Avanzado: Añadimos un marco a todo lo anterior.

this.createEmptyMovieClip(“cargador”, 1);
this.createTextField(“porcentaje”, 2, 0, 0, “200″, “16″);
this.cargador._x = 0;
this.cargador._y = 0;
this.ancho = 300;
this.alto = 366;
this.cargador.loadMovie(“../img/robot_flasxl.jpg”);
//
with (this) {
lineStyle(2, 0×000000, 100);
moveTo(this.cargador._x, this.cargador._y);
lineTo(this.cargador._x+this.ancho, this.cargador._y);
lineTo(this.cargador._x+this.ancho, this.cargador._y+this.alto);
lineTo(this.cargador._x, this.cargador._y+this.alto);
lineTo(this.cargador._x, this.cargador._y);
}
this.onEnterFrame = function() {
this.cargador.percent = (this.cargador.getBytesLoaded()/this.cargador.getBytesTotal())*100;
if (!isNan(this.cargador.percent)) {
this.porcentaje.text = Math.round(this.cargador.percent)+” %”;
}
if (this.cargador.percent == 100) {
delete this.onEnterFrame;
}
};

Final: Para rematar la faena incorporamos un efecto fadein.

//función FX fadeIn
//Previamente hemos asignado el valor 0 al clip de película cargador
alfa = function (clip) {
this.createEmptyMovieClip(“loop”, 3);// creamos un clip de pelicula para hacer un loop
loop.onEnterFrame = function() {
clip._alpha += 10;
if (clip._alpha>=100) {
delete loop.onEnterFrame;// eliminar loop
}
};
};
// crear un clip vacio para cargar la imagen
this.createEmptyMovieClip(“cargador”, 1);
// crear un campo de texto para mostrar el porcentaje cargado de la imagen
this.createTextField(“porcentaje”, 2, 10, 10, 200, 16);
// situamos el clip de película en la posición que nos conviene
this.cargador._x = 0;
this.cargador._y = 0;
// este es el tamaño de la imagen, nos hace falta paa crear el marco
this.ancho = 300;
this.alto = 366;
// cargar la imagen
this.cargador.loadMovie(“../img/robot_flasxl.jpg”);
this.cargador._alpha = 0;
// dibujar marco
with (this) {
lineStyle(2, 0×000000, 100);
moveTo(this.cargador._x, this.cargador._y);
lineTo(this.cargador._x+this.ancho, this.cargador._y);
lineTo(this.cargador._x+this.ancho, this.cargador._y+this.alto);
lineTo(this.cargador._x, this.cargador._y+this.alto);
lineTo(this.cargador._x, this.cargador._y);
}
// precarga
this.onEnterFrame = function() {
// calculamos el porcentaje cargado
this.cargador.percent = (this.cargador.getBytesLoaded()/this.cargador.getBytesTotal())*100;
// mostrar porcentaje
if (!isNan(this.cargador.percent)) {
this.porcentaje.text = Math.round(this.cargador.percent)+” %”;
}
// imagen cargada
// cargamos la función para el fx y eliminamos el campo que muestra el porcentaje
if (this.cargador.percent == 100) {
this.porcentaje.removeTextField()
alfa(this.cargador);
delete this.onEnterFrame;
}
};

Ver fuente

También podemos cargar imagenes de una forma muy simple y efectiva, aplicable a otros elementos externos.

Un clip vacío lo colocamos en las coordenadas que nos intere a partir de las cuales se cargara nuestra imagen.

1. Creamos el clip vacío (ej. ·”clip_vacio”).

2. Lo colocamos en nuestro proyecto en la coordenada correspondiente.

3. En las propiedades del clip insertamos un nombre de instancia (ej. “imagen”) .

4. Usamos el siguiente código, directamente o en un botón, para cargar la imagen (ej. “img.jpg”).

_root.imagen.loadMovie(“img.jpg”);

Esta entrada fue publicada en ActionScript, Adobe Flash. Guarda el enlace permanente.Tanto los comentarios como los trackbacks están cerrados.
FadeOut-Thumbshots Plugin by Thomas Schulte