# Random question

**URL:** <https://forum.kirupa.com/t/random-question/45342>\
**Category:** Uncategorized\
**Created:** [March 13, 2004, 1:19pm UTC](https://forum.kirupa.com/t/random-question/45342 "2004-03-13T13:19:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elmago](https://avatars.discourse-cdn.com/v4/letter/e/848f3c/32.png) [@elmago](https://forum.kirupa.com/u/elmago)\
**Post date:** [March 13, 2004, 1:19pm UTC](https://forum.kirupa.com/t/random-question/45342/1 "2004-03-13T13:19:43Z")

</div>

I would like a backgroundpic to fade in and out. To make it mysterious I would like this to occour in random time. How do I do this the best way?

thx

---

<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:** [March 13, 2004, 3:36pm UTC](https://forum.kirupa.com/t/random-question/45342/2 "2004-03-13T15:36:05Z")

</div>

one way of doing it…

1. make your pic a MovieClip
2. then inside give it this actionscript:

```auto
onClipEvent (load) {
Rate = 2; // however fast you want your pic to fade in/out
fade = Rate; //you'll see why in a sec
}
onClipEvent (enterFrame) {
if (!random(1000)) {
fadeRate = -Rate;
}
_alpha += fadeRate;
if (_alpha <= 0) {
fadeRate = Rate;
}
}

```

not the only, most efficient way, but this code basically loops until random(1000) hits 0 at which point the image fades out. once it is completely faded out, it fades back in and waits yet again. Mind you, this code is spontaneous so it may fade back out as it’s fading in, since it uses a random number generator.

---

<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:** [March 13, 2004, 7:27pm UTC](https://forum.kirupa.com/t/random-question/45342/3 "2004-03-13T19:27:24Z")

</div>

Hi thoriphes  
It´s pretty mutch what I want to happen but there is one thing that feels pretty wierd and that is that the pic gets overexposed (excuse my bad english) when it fades over 100% which I dont like. Im not really the code guy so do you mind explaining the if(!random(1000)) line for me. Im really thankful for all your help.

thanx

---

<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:** [March 13, 2004, 7:32pm UTC](https://forum.kirupa.com/t/random-question/45342/4 "2004-03-13T19:32:07Z")

</div>

I forgot… is there a way to make it wait when it´s faded out?
