# Randomly load JPEG with fade

**URL:** <https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534>\
**Category:** Uncategorized\
**Created:** [February 10, 2004, 3:06am UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534 "2004-02-10T03:06:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![acaraciolo](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@acaraciolo](https://forum.kirupa.com/u/acaraciolo)\
**Post date:** [February 10, 2004, 3:06am UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534/1 "2004-02-10T03:06:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2004, 3:59am UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534/2 "2004-02-10T03:59:21Z")

</div>

Please use better titles for your threads.  
And for the banner thing, play around with something like this:

```auto
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();

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2004, 7:52am UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534/3 "2004-02-10T07:52:18Z")

</div>

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();}

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2004, 1:34pm UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534/4 "2004-02-10T13:34:54Z")

</div>

Thanks for reminding me eyez, i was so tired when i posted on this thread that i completely forgot to change its title. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2004, 7:38pm UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534/5 "2004-02-10T19:38:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2004, 10:25pm UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534/6 "2004-02-10T22:25:13Z")

</div>

don’t worry, noone uses search anyway… 🙂 or rather ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 11, 2004, 2:43am UTC](https://forum.kirupa.com/t/randomly-load-jpeg-with-fade/42534/7 "2004-02-11T02:43:11Z")

</div>

Welcome acaraciolo 🙂  
Enjoy the forums!
