Tengo un banner rotativo, carga JPGs externos, botones en la misma cantidad de los JPGs internos, un setInterval que permite rotar los banners, un hit que levanta la URL desde el AS.
Hay un MC por imagen instanciado "img01, img02, etc", un MC que es el hit instanciado "hoverClick", los botones "btn01, btn02, etc" en celeste, los botones "btn01Press, btn02Press, etc" en blanco.
Este es el código:
Código :
//This is needed in order to take advantage of the tween function
import mx.transitions.Tween;
//This hides the 3 grow bars from sight
btn01._alpha = 0;
btn02._alpha = 0;
btn03._alpha = 0;
btn04._alpha = 0;
//btn_play._alpha = 0;
hoverClick._alpha = 0;
adPause = false;
img02._alpha = 0;
img03._alpha = 0;
img04._alpha = 0;
img01.loadMovie("/images/banner01.jpg"); //+ _level0.imageOne);
img02.loadMovie("/images/banner02.jpg"); //+_level0.imageTwo);
img03.loadMovie("/images/banner03.jpg"); //+_level0.imageThree);
img04.loadMovie("/images/banner04.jpg"); //+_level0.imageFour);
url1 = "masymejor/index.asp"; //+_level0.linkOne;
url2 = "redempleo/index.asp"; //+_level0.linkTwo;
url3 = "inspeccion/pnrt.asp"; //+_level0.linkThree;
url4 = "redifp/index.asp"; //+_level0.linkThree;
//These are the default settings. the adInterval needs to change to a flash var once this is working
barHeight = 100
//adInterval = _level0.interval;
currentCount = 0;
barCount = 0;
whichAd = 1;
//timer_txt.text = currentCount;
//This is the counter that handles the seconds
timer = setInterval(countDown, 3000);
//This is the timer that handles the growth of the progress bars
barTimer = setInterval(growBar, 100);
// the natural progression throught the 3 ads
function countDown() {
currentCount++;
if (currentCount >= adInterval) {
timer = clearInterval(timer);
barCount = 0;
resetTimer();
}
}
// this is the timer that allows the bars to grow at a faster pace than the ad numbers. Not sure why /6 works, it should be /10 but whatever...
function growBar() {
barCount++;
if(whichAd == 1){
btn01._alpha = 100;
TimeBar_btn01._yscale= 100/(adInterval/(barCount/6));
btn02._alpha = 0;
btn03._alpha = 0;
btn04._alpha = 0;
} else if(whichAd == 2){
btn02._alpha = 100;
TimeBar_btn02._yscale= 100/(adInterval/(barCount/6));
btn01._alpha = 0;
btn03._alpha = 0;
btn04._alpha = 0;
} else if(whichAd == 3){
btn03._alpha = 100;
TimeBar_btn03._yscale= 100/(adInterval/(barCount/6));
btn01._alpha = 0;
btn02._alpha = 0;
btn04._alpha = 0;
} else if(whichAd == 4){
btn04._alpha = 100;
TimeBar_btn04._yscale= 100/(adInterval/(barCount/6));
btn01._alpha = 0;
btn02._alpha = 0;
btn03._alpha = 0;
} else {
whichAd = 1;
}
}
// This is triggered via the countDown function
function resetTimer(){
currentCount = 0;
whichAd++;
timer = setInterval(countDown, 3000);
changeNextImage();
}
function changeNextImage()
{
if (img01._alpha >0)
{
fadeOutImages(img01);
fadeInImages(img02);
}
else if (img02._alpha >0)
{
fadeOutImages(img02);
fadeInImages(img03);
}
else if (img03._alpha >0)
{
fadeOutImages(img03);
fadeInImages(img04);
}
else if (img04._alpha >0)
{
fadeOutImages(img04);
fadeInImages(img01);
}
}
//This is triggered by the clicking of one of the buttons
function changeAd(adNumber)
{
if (adPause == false)
{
timer = clearInterval(timer);
timer = clearInterval(barTimer);
currentCount = 0;
whichAd = adNumber;
timer = setInterval(countDown, 3000);
barTimer = setInterval(growBar, 100);
barCount = 0;
}
else
{
currentCount = 0;
whichAd = adNumber;
timer = setInterval(countDown, 3000);
barTimer = setInterval(growBar, 100);
barCount = 0;
adPause = false
//btn_play._alpha = 0;
//btn_pause._alpha = 100;
}
}
// This changes the display to ad number 1
btn01Press.onPress = function()
{
changeAd(1);
if (img02._alpha >0)
{
fadeOutImages(img02);
}
else if (img03._alpha >0)
{
fadeOutImages(img03);
}
else if (img04._alpha >0)
{
fadeOutImages(img04);
}
fadeInImages(img01);
}
// This changes the display to ad number 2
btn02Press.onPress = function()
{
changeAd(2);
if (img01._alpha >0)
{
fadeOutImages(img01);
}
else if (img03._alpha >0)
{
fadeOutImages(img03);
}
else if (img04._alpha >0)
{
fadeOutImages(img04);
}
fadeInImages(img02);
}
// This changes the display to ad number 3
btn03Press.onPress = function()
{
changeAd(3);
if (img01._alpha >0)
{
fadeOutImages(img01);
}
else if (img02._alpha >0)
{
fadeOutImages(img02);
}
else if (img04._alpha >0)
{
fadeOutImages(img04);
}
fadeInImages(img03);
}
// This changes the display to ad number 4
btn04Press.onPress = function()
{
changeAd(4);
if (img01._alpha >0)
{
fadeOutImages(img01);
}
else if (img02._alpha >0)
{
fadeOutImages(img02);
}
else if (img03._alpha >0)
{
fadeOutImages(img03);
}
fadeInImages(img04);
}
hoverClick.onRollOver = function()
{
this.gotoAndPlay(2);
if (adPause == false)
{
//btn_play._alpha = 100;
//btn_pause._alpha = 0;
timer = clearInterval(timer);
timer = clearInterval(barTimer);
adPause = true
}
}
hoverClick.onPress = function()
{
if(whichAd == 1){
getURL(url1);
}
if(whichAd == 2){
getURL(url2);
}
if(whichAd == 3){
getURL(url3);
}
if(whichAd == 4){
getURL(url4);
}
}
hoverClick.onRollOut = function(){
this.gotoAndStop(1);
//btn_play._alpha = 0;
//btn_pause._alpha = 100;
timer = setInterval(countDown, 3000);
barTimer = setInterval(growBar, 100);
//adPause = false;
}
function fadeOutImages(whatImage)
{
var alpha_out_interval:Number = setInterval(fadeOutImage, 20, whatImage);
function fadeOutImage(target_mc:MovieClip):Void
{
target_mc._alpha -= 5;
if (target_mc._alpha <= 0)
{
target_mc._visible = false;
clearInterval(alpha_out_interval);
}
}
}
function fadeInImages(whatImage)
{
var alpha_in_interval:Number = setInterval(fadeInImage, 20, whatImage);
function fadeInImage(target_mc:MovieClip):Void
{
target_mc._visible = true;
target_mc._alpha += 5;
if (target_mc._alpha >= 100)
{
clearInterval(alpha_in_interval);
}
}
}
Tengo un problema: después de x tiempo empieza a pasar más rápido y sin orden y sin respetar las funciones.
Por otro lados... cómo puedo hacer para que las imágenes, los botones y las url carguen por xml?
abrazos, gracias.
