# Load random pix

**URL:** <https://forum.kirupa.com/t/load-random-pix/288555>\
**Category:** flash\
**Created:** [May 18, 2009, 9:46am UTC](https://forum.kirupa.com/t/load-random-pix/288555 "2009-05-18T09:46:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![longneck](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@longneck](https://forum.kirupa.com/u/longneck)\
**Post date:** [May 18, 2009, 9:46am UTC](https://forum.kirupa.com/t/load-random-pix/288555/1 "2009-05-18T09:46:45Z")

</div>

Hi all,

I have this site that loads random pix from different folders (not xml). What I would like but can’t seem to get to work, is for all the different images to be displayed before they are loaded again. If there for instance are 8 images in a folder I want those 8 images to be loaded – still randomly – before an image are loaded for the second time.

Heres the code I’m using:

[COLOR=“Blue”]\*var maxVal = 8;  
var oldVar = 8;  
var newVar = 0;  
var si = 0;

function getImage() {  
newVar = Math.floor(Math.random() \* maxVal);   
if (newVar == oldVar) {   
getImage();   
} else {   
oldVar = newVar;   
container\_mc.loadMovie (“bryghuset/foto” + newVar + “.jpg”);   
container\_mc.\_alpha = 0;   
this.onEnterFrame = function () {   
if (container\_mc.\_width \> 0) {   
container\_mc.onEnterFrame = fadeIn;   
delete this.onEnterFrame;   
}  
}  
}  
}

function fadeIn () {  
if (this.\_alpha \<= 100) {  
this.\_alpha += 5;  
} else {  
this.\_alpha = 100;  
delete this.onEnterFrame;  
si = setInterval(fadeOut, 2000);  
movieclip  
}  
}

function fadeOut () {  
clearInterval(si);  
container\_mc.onEnterFrame = function() {  
if (this.\_alpha \>= 0) {  
this.\_alpha -= 5;  
} else {  
this.\_alpha = 0;  
delete this.onEnterFrame;  
getImage();  
image  
}  
}  
}

getImage();\*[/COLOR]

If anyone could help out I would be very greatful.

/Simon
