# Image gallery - random array

**URL:** https://forum.kirupa.com/t/image-gallery-random-array/38175
**Category:** Uncategorized
**Created:** [December 19, 2003, 1:14am UTC](https://forum.kirupa.com/t/image-gallery-random-array/38175 "2003-12-19T01:14:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![norm1252003](https://avatars.discourse-cdn.com/v4/letter/n/977dab/32.png) [@norm1252003](https://forum.kirupa.com/u/norm1252003)
#### Post date: [December 19, 2003, 1:14am UTC](https://forum.kirupa.com/t/image-gallery-random-array/38175/1 "2003-12-19T01:14:01Z")

</div>

hey all,

I found this code online. it is for a image gallery that fades in and out as it transition from one image to the next… the images are load through an array command… it loads the first image, etc… what I wanted to know is where should i put a Math.floor(Math.random()\*this.pic\_arr.length); in the string of code… to make the gallery start randomly in the array and then continue onto the next image… also, for some reason, there is not a common directory for all the images, like this script:

this.pathToPics = “bannerimage/”;  
this.pArray = [“pic2.jpg”,“pic3.jpg”,“pic4.jpg”,“pic5.jpg”];  
this.pIndex = Math.floor(Math.random()\*this.pArray.length);  
loadMovie(this.pathToPics+this.pArray[this.pIndex], this.menu.photo);

“bannerimage” is the common directory…

here is the code from the tutorial… if someone could help me with these two problems, that would be great…

here is the code in the main stage…

pic\_arr = [“flower\_pink.jpg”, “flower\_yellow.jpg”, “flower\_purple.jpg”, “flower\_red.jpg”, “flower\_orange.jpg”];  
color\_arr = [0xf75eb0, 0xf6f818, 0xbb57c8, 0xdf1734, 0xfe9809];

blank\_mc.attachMovie(“slideshow”, “uuShow”, 1, {  
\_x:0, \_y:0, \_visible:false, fps:12, nFrames:24, alphaIncr:10,  
slides\_arr:pic\_arr, slideDepth:50, repeat:true});

blank\_mc.uuShow.addListener(blank\_mc);

blank\_mc.onSlideLoaded = function(i) {  
(new Color(this.\_parent[“dot”+i+"\_mc"])).setRGB(color\_arr\*);  
};

blank\_mc.onAllSlidesLoaded = function() {  
this.uuShow.\_visible = true;  
this.uuShow.beginTransitions();  
};

blank\_mc.onShowOver = function() {  
//set repeat:false in uuShow for this to be called  
//trace(‘slideshow is over’);  
};

code found in the slideshow component

#initclip 1  
Slideshow = function() {  
ASBroadcaster.initialize(this);  
this.loadInSeq(0);  
}

Slideshow.prototype = new MovieClip ();

Slideshow.prototype.loadInSeq = function(i) {  
var slide = this.createEmptyMovieClip(“slide” + i, this.slideDepth++);  
// hide all slides loading on top of first one  
if (i \> 0) slide.\_alpha = 0;  
slide.loadMovie(this.slides\_arr\*);  
checkLoadedID = setInterval(function(i, mc) {  
if (mc[“slide” + i].\_width \> 0) {  
mc[“slide” + i].\_visible = true;  
mc.broadcastMessage(“onSlideLoaded”, i);  
clearInterval(checkLoadedID);  
// start next one loading (if not last)  
if (i \< mc.slides\_arr.length-1) {  
mc.loadInSeq(i + 1);  
} else {  
mc.broadcastMessage(“onAllSlidesLoaded”);  
}   
}  
}, 1000/this.fps, i, this);

};

Slideshow.prototype.beginTransitions = function() {  
var holdTimeMs = 1000 \* this.nFrames / this.fps;  
holdID = setInterval(function(mc) { mc.activateInSeq(0); clearInterval(holdID); }, holdTimeMs, this);  
};

Slideshow.prototype.activateInSeq = function(i) {  
if (++i \< this.slides\_arr.length) {  
this[“slide” + i].\_alpha = 0;  
this[“slide” + i].swapDepths(this.slideDepth++);  
this.onEnterFrame = function() {  
if (this[“slide” + i].\_alpha \>= 95) {  
var counter = this.nFrames;  
this.onEnterFrame = function() {  
if (!counter–) {  
delete this.onEnterFrame;  
this.activateInSeq(i);  
}  
};  
} else {  
this[“slide” + i].\_alpha += this.alphaIncr;  
}  
};  
} else {  
if (this.repeat) this.activateInSeq(-1);  
else this.broadcastMessage(“onShowOver”);  
}  
};

Object.registerClass(“slideshow”, Slideshow);  
#endinitclip

---

<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: [December 23, 2003, 2:52am UTC](https://forum.kirupa.com/t/image-gallery-random-array/38175/2 "2003-12-23T02:52:54Z")

</div>

1. Right here.  
[AS]  
Slideshow.prototype.activateInSeq = function() {  
var i = Math.floor(Math.random()\*this.pic\_arr.length);  
if (++i \< this.slides\_arr.length) {  
this[“slide” + i].\_alpha = 0;  
this[“slide” + i].swapDepths(this.slideDepth++);  
this.onEnterFrame = function() {  
if (this[“slide” + i].\_alpha \>= 95) {  
var counter = this.nFrames;  
this.onEnterFrame = function() {  
if (!counter–) {  
delete this.onEnterFrame;  
this.activateInSeq(i);  
}  
};  
} else {  
this[“slide” + i].\_alpha += this.alphaIncr;  
}  
};  
} else {  
if (this.repeat) this.activateInSeq(-1);  
else this.broadcastMessage(“onShowOver”);  
}  
};  
[/AS]
2. Put them in the same directory.  
(Sorry but that is the best solution.)

:)Clown
