Hi all,
I have writen a block of code to fades images in and out in a loop and text which fade in and out on top of it.
So image fades in, when at 100, text fades in on top and then fade out, the image fades out. New image fades in and text, and so on.
This all works fine but the code seems quite lengthy, so I wonder if anyone could see a way of shortening the code or making it more readable.
[AS]
img = [marine_mc, prop_mc, re_mc];
txtImg = [marineTxt_mc, propTxt_mc, reTxt_mc];
// hide images and text to start
for (n=0; n<=img.length; n++) {
img[n]._alpha = 0;
txtImg[n]._alpha = 0;
}
var i = 0;
var delay = 2000;//time betweeen images fading
//var txtDelay = ?To alter fading text time.
fadeIn(img*, 10);
function fadeIn(target, num) {
target.onEnterFrame = function() {
target._alpha += num;
if (target._alpha>=100) {
target._alpha = 100;
delete this.onEnterFrame;
timeDelay = setInterval(out, delay);
txtIn(txtImg*, 20);
}
};
}
function out() {
fadeOut(img*, 10);
}
function txtIn(target, num) {
target.onEnterFrame = function() {
target._alpha += num;
if (target._alpha>=100) {
target._alpha = 100;
delete this.onEnterFrame;
txtOutInt = setInterval(txtFadeOut, (delay/2));
}
};
}
function txtFadeOut() {
txtOut(txtImg*, 10);
}
function txtOut(target, num) {
target.onEnterFrame = function() {
target._alpha -= num;
if (target._alpha<=0) {
target._alpha = 0;
this.onEnterFrame = null;
clearInterval(txtOutInt);
}
};
}
function fadeOut(target, num) {
target.onEnterFrame = function() {
target._alpha -= num;
if (target._alpha<=0) {
target._alpha = 0;
this.onEnterFrame = null;
clearInterval(timeDelay);
if (i>=img.length-1) {
i = 0;
} else {
i++;
}
fadeIn(img*, 10);
}
};
}
[/AS]