[FONT=Arial][SIZE=3]Platform: Flash 8, AS2. I have a script that fades in a random image from an array, and then loads the same image in another MC in the layer below so the transition from one image to the next does not show a white background.
The problem is that while it works perfectly as a standalone .SWF and also in Firefox, I’m getting a white flash between images in IE, and it’s erratic in Opera also. Anyone know a reason for this?
This is the main code, and I’ve also attached the .FLA. You will need 5 image files in a subdirectory called “images” to run it. I’m sure the code could be simpler, but right now I’m just concerned about why it won’t run the same across different browsers. Thx.
stop();
var picNumber:Number = 0;
var i:Number = 0;
var counter:Number = 0;
var numArray:Array = randomNumber(); //generate a random sequence of 5 numbers between 0 and 4
//image list arrays are just a list of individual image files
imageList1 = ["images/header00.jpg", "images/header01.jpg", "images/header02.jpg", "images/header03.jpg", "images/header04.jpg"];
var mc_pic1:MovieClip;
var mc_holder:MovieClip;
mc_pic1._alpha = 0; //set alpha to 0 so layer 'picture' can show through
function picFade(mc_pic,lastImage) {
//Fades the image in
mc_pic._alpha = 0;
this.onEnterFrame = function() {
mc_pic._alpha += 5;
if (mc_pic._alpha >= 100) {
_root.mc_holder.loadMovie(lastImage);
}
}
if (counter>=4) {
//If counter is >= 4, that means all 5 images have been displayed
var interval:Number = setInterval(function ():Void {
clearInterval(interval);
gotoAndPlay(2); //Just restarts this frame
}, 10); //This code inserts a pause that was needed in a previous version. The number has been reduced to '10' from '2000' to eliminate any pause
}
counter++;
}
function randomNumber() {
var pics1:Array = new Array("1", "2", "3", "4", "5");
// This was developed to display a random image from an array of 5
var picNumbersUsed:Array = new Array();
var randomNum:Number = Math.ceil(Math.random()*pics1.length-1);
//generates a random number less than 5
var numbers:Number = picNumbersUsed.push(randomNum);
//pushes that number into the new array
do {
var randomNum2:Number = Math.ceil(Math.random()*pics1.length-1);
//generates a second random number, compare it to the numbers already in the array, and add it if it's not already there
if ((randomNum2 != picNumbersUsed[0]) and (randomNum2 != picNumbersUsed[1]) and (randomNum2 != picNumbersUsed[2]) and (randomNum2 != picNumbersUsed[3]) and (randomNum2 != picNumbersUsed[4]) and (randomNum2 != picNumbersUsed[5])) {
numbers = picNumbersUsed.push(randomNum2);
}
} while (numbers<5);
//we only want 5 numbers in the array
//trace ("picNumbersUsed = " + picNumbersUsed);
return picNumbersUsed;
}
function autoImage() {
var picNumber:Number = numArray*;
//numArray is an array of 5 numbers generated from the randomNumber function
i++;
switch (picNumber) {
//picNumber var determines which image to display first
case 0 :
//trace ("case 0 (5th image): i = "+i);
_root.mc_pic1.loadMovie(imageList1[numArray[4]]);
//loads image from array into MC mc_pic1 on stage
picFade(mc_pic1,imageList1[numArray[4]]);
//calls fade in function and passes the MC name to be faded in and the name of the last image displayed
break;
case 1 :
//trace ("case 1 (1st image): i = "+i);
_root.mc_pic1.loadMovie(imageList1[numArray[0]]);
picFade(mc_pic1,imageList1[numArray[0]]);
break;
case 2 :
//trace ("case 2 (2nd image): i = "+i);
_root.mc_pic1.loadMovie(imageList1[numArray[1]]);
picFade(mc_pic1,imageList1[numArray[1]]);
break;
case 3 :
//trace ("case 3 (3rd image): i = "+i);
_root.mc_pic1.loadMovie(imageList1[numArray[2]]);
picFade(mc_pic1,imageList1[numArray[2]]);
break;
case 4 :
//trace ("case 4 (4th image): i = "+i);
_root.mc_pic1.loadMovie(imageList1[numArray[3]]);
picFade(mc_pic1,imageList1[numArray[3]]);
break;
}
}
clearInterval(autoInterval);
autoInterval = setInterval(autoImage, 5000);
//fires autoImage every 5 seconds
[/SIZE][/FONT]