| Mostrar banners Flash en forma aleatoria
En otra ocasión mostramos este
mismo script pero para mostrar banners de formato GIF en forma aleatoria. Nos ha llegado
la duda de cómo mostrar banners aleatorios realizados en Flash, por lo que hemos adaptado
el código para poder hacerlo.
Funcionamiento
El JavaScript selecciona en forma aleatoria un número que va de 1 a la cantidad
de banners que queremos mostrar. Luego realiza comparaciones con la sentencia IF para definir las variables que contendrán la información del banner: en este caso son flash
con el nombre del archivo swf, y width y height con las
medidas del mismo.
// En la variable
"banner" definimos la cantidad de banners, en este caso serán 3
var banners = 3;
...
// Definimos las propiedades del banner en cada posibilidad
// Archivo SWF, ancho y alto.
if (ad==1) {
flash="banner1.swf"
width="468";
height="60";
}
if (ad==2) {
flash="banner2.swf"
width="468";
height="60";
}
if (ad==3) {
flash="banner3.swf"
width="468";
height="60";
}
...
Por último, deberemos imprimir el código
html para insertar el archivo Flash.
Código completo
El siguiente JavaScript deberá ser ubicado en la parte de la página que
queremos que se muestre:
<SCRIPT LANGUAGE="JavaScript">
// Realizado por: Fabian Muller
// WebExperto.com - Ayuda al webmaster en español
// Comienzo
var banners = 3;
var ahora = new Date()
var segundos = ahora.getSeconds()
var ad = segundos % banners;
ad +=1;
if (ad==1) {
flash="banner1.swf"
width="468";
height="60";
}
if (ad==2) {
flash="banner2.swf"
width="468";
height="60";
}
if (ad==3) {
flash="banner3.swf"
width="468";
height="60";
}
document.write('<center>');
document.write('<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=' + width + ' height=' + height + ' CODEBASE=\"http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0\">');
document.write('<PARAM NAME=\"MOVIE\" VALUE=\"' + flash + '\">');
document.write('<PARAM NAME=\"PLAY\" VALUE=\"true\">');
document.write('<PARAM NAME=\"LOOP\" VALUE=\"true\">');
document.write('<PARAM NAME=\"QUALITY\" VALUE=\"high\">');
document.write('<EMBED SRC=' + flash + ' width=' + width + ' height=' + height + ' PLAY=\"true\" LOOP=\"true\" QUALITY=\"high\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi? P1_Prod_Version=ShockwaveFlash\">');
document.write('</EMBED>');
document.write('</OBJECT>');
document.write('</center>');
// Fin
</SCRIPT> |