A call to all for help… Is there a way to use ActionScript to randomly load JPEG files so that one fade’s out smoothly while the other fade’s in… without a button or mouse trigger, like in a banner? I posted this question the other day but so far have received 0 replys. Not sure if I’m asking something extreemly difficult or so darn simple everyone figures it should be obvious! I tried using setInterval with a function call and it works sort of but caused other problems in the movie…Please, if you have any suggestions I would be very greatful.
Please use better titles for your threads.
And for the banner thing, play around with something like this:
Array.prototype.randomize = function() {
return this.sort(function (a, b) {
return (Math.floor(Math.random()*2) == 0) ? 1 : -1;
});
};
movies_array = ["image1", "image2", "image3", "image4"];//array containing your image files without the .jpg extension
movies_array.randomize();//randomize the array everytime the movie runs
index = 0;
speed = 10;//fading speed
seconds = 3;//seconds before the picture fadeout
this.createEmptyMovieClip("container", 0);
this.createEmptyMovieClip("loader", 1);
function preload() {
loader.onEnterFrame = function() {
var l, t;
l = container.getBytesLoaded();
t = container.getBytesTotal();
if (t && l == t) {
delete this.onEnterFrame;
container._alpha = 0;
my_interval = setInterval(fadeIn, 50);
}
};
}
function fadeIn() {
if (container._alpha>100) {
clearInterval(my_interval);
my_interval = setInterval(pause, seconds*1000);
} else {
container._alpha += speed;
}
}
function pause() {
clearInterval(my_interval);
my_interval = setInterval(fadeOut, 50);
}
function fadeOut() {
if (container._alpha<0) {
clearInterval(my_interval);
loadPicture();
} else {
container._alpha -= speed;
}
}
function loadPicture() {
container.loadMovie(movies_array[index]+".jpg");
preload();
index == movies_array.length-1 ? index=0 : ++index;
}
loadPicture();
claudio, you may want to fix the titles at the same time, rules are up there to be followed, so if (typeof(title)=bad){changeIt();}
Thanks for reminding me eyez, i was so tired when i posted on this thread that i completely forgot to change its title.
Claudio… Thanks for your help and I apologize for the title. I had posted an earlier request with the title: Loading random jpg files with fadin/out and received no response. That was only my second post on this BB, and I have only been using FLASH for less then two months. Once again sorry. - Al
don’t worry, noone uses search anyway… or rather
Welcome acaraciolo
Enjoy the forums!