# Arrays, random, fading

**URL:** <https://forum.kirupa.com/t/arrays-random-fading/150651>\
**Category:** Uncategorized\
**Created:** [June 9, 2005, 9:48am UTC](https://forum.kirupa.com/t/arrays-random-fading/150651 "2005-06-09T09:48:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FlashDiva](https://avatars.discourse-cdn.com/v4/letter/f/c0e974/32.png) [@FlashDiva](https://forum.kirupa.com/u/FlashDiva)\
**Post date:** [June 9, 2005, 9:48am UTC](https://forum.kirupa.com/t/arrays-random-fading/150651/1 "2005-06-09T09:48:46Z")

</div>

Hello all,

heres the situation, I am trying to make about 20 movie clips fade in and out randomly.This is the code I have and I thought it would work. I have been researching arrays, randomizing, loops and mroe for so long that my brain is no longer functional. If a scripting guru could help me I would be extremely appreciative. Thanks a bunch!!

This is on the main time line and I have a movieclip name grid on the stage. grid has all the mcs in it.

gridblocks = new Array();  
for (var i in grid) {  
grid\*.\_alpha=0;  
grid\*.fade=0;  
gridblocks.push(grid\*);  
}  
fadeinCount=0;  
this.onEnterFrame = function() {  
count=random(gridblocks.length);  
gridblocks[count].fade=1;  
for (var i in gridblocks) {  
if (gridblocks\*.fade==1) {  
gridblocks\*.\_alpha ++;  
// check if all blocks are done  
if (gridblocks\*.\_alpha==100) {  
fadeinCount++;  
}  
}  
else if (gridblocks\*.fade==100) {  
gridblocks\*.\_alpha–;  
}  
}  
}

Ok, I have kept looking and I found some more code…it is great except I want my objects to do this randomly and wihtout button prompting…Can anyone help I am desperate…

object1.\_alpha = 0;  
//////////////////////////////  
//////////////////////////////  
MovieClip.prototype.alphaOut = function(alpha) {  
this.onEnterFrame = function() {  
this.\_alpha = alpha-(alpha-this.\_alpha)/1.2;  
if (Math.abs(this.\_alpha-alpha)\<1) {  
this.\_alpha = alpha;  
delete this.onEnterFrame;  
}  
};  
};  
MovieClip.prototype.alphaIn = function(alpha) {  
this.onEnterFrame = function() {  
this.\_alpha = alpha-(alpha-this.\_alpha)/1.2;  
if (Math.abs(this.\_alpha-alpha)\<1) {  
this.\_alpha = alpha;  
delete this.onEnterFrame;  
}  
};  
};  
//////////////////////////////  
//////////////////////////////  
fadeIn.onPress = function() {  
object1.alphaIn(100)  
}  
fadeOut.onPress = function() {  
object1.alphaOut(0);  
};
