# \[FMX\]Random alpha fade in and out

**URL:** <https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555>\
**Category:** flash\
**Created:** [August 29, 2004, 5:23am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555 "2004-08-29T05:23:43Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![dboers](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dboers](https://forum.kirupa.com/u/dboers)\
**Post date:** [August 29, 2004, 5:23am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/1 "2004-08-29T05:23:43Z")

</div>

I have a picture on the stage that is coverd by 24 small squares (suare01, square02,…square24) The alpha property for all squares is50. I would like the squares randomly fade to alpha 0 (stay on alpha 0 for approx. 8 seconds) and then fade back to alpha 50 again, while another one fade to alpha 0

Thanks in advance

---

<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:** [August 30, 2004, 4:56am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/2 "2004-08-30T04:56:29Z")

</div>

On this page is an example of what I mean:  
[http://www.tempur.com/page117.asp?lang=cypern](http://www.tempur.com/page117.asp?lang=cypern)

---

<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:** [August 30, 2004, 6:58am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/3 "2004-08-30T06:58:53Z")

</div>

Hi  
You could use something like the moviclip tweening class or the one from [http://laco.wz.cz/tween/?page=docs/tween](http://laco.wz.cz/tween/?page=docs/tween)  
which is very handy.

square1.tween(’\_alpha’, 100,2,‘linear’,8)\*;

Would give you a basic one way fade from 50 too 100 over 2 seconds after 8 seconds. With a setInterval, callback or set of variables in a loop you should be able to set any pattern up.

Findal  
[www.fndzinz.com](http://www.fndzinz.com)

-

---

<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:** [August 30, 2004, 7:19am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/4 "2004-08-30T07:19:26Z")

</div>

I just downloaded the extension from laco, but it is quit new to me because I actualy never worked with extensions before. So I not realy know what to do next  
Do I just drop that extension on a movie clip or…?

---

<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:** [August 30, 2004, 7:53am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/5 "2004-08-30T07:53:06Z")

</div>

Hi [Findal](http://www.tempur.com/page117.asp?lang=cypern)

I just find out that the extension I downloaded is for MX 2004 which I don’t have. Is there another way?

---

<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:** [August 30, 2004, 8:17am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/6 "2004-08-30T08:17:14Z")

</div>

Hi  
#include “lmc\_tween.as” for ActionScript 2.0 (runs fine on Flash Player 6) or  
#include “lmc\_tween\_as1.as” for ActionScript 1.0 you can use following methods for every MovieClip: see installion page [http://laco.wz.cz/tween/?page=docs/install](http://laco.wz.cz/tween/?page=docs/install)  
(I believe there is actually and .mxp on the Macromedia site that skips the include line)

Just check out the instalation section and a few examples.  
You put the “lmc\_tween.as” file in the same folder as the .swf file, and use the include line as you first line of code. Then any of the methods of the class are available to use where ever you want in your script.

🙂  
Findal

---

<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:** [August 30, 2004, 8:49am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/7 "2004-08-30T08:49:11Z")

</div>

Hi Findal,

Sorry! Maybe I’m realy stupid but I put “lmc\_tween.as” file in the same folder as my swf, but nothing happen. The fade is not working.I don’t know what I’m doing wrong ?

---

<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:** [August 30, 2004, 8:59am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/8 "2004-08-30T08:59:40Z")

</div>

Try putting your boxes in a movie clip named “boxes”, then name all the boxes like “one, two, and so on…” then go back to the main timeline and put this

```auto
#include "lmc_tween_as1.as"

```

on a layer named actions. double click the boxes movie clip and make a layer actions and paste this

```auto

one.alphaTo(0,4,"",1);
ten.alphaTo(0,4,"",3);
fourteen.alphaTo(0,4,"",5);
eleven.alphaTo(0,4,"",7);
eight.alphaTo(0,4,"",9);
two.alphaTo(0,4,"",11);
nine.alphaTo(0,4,"",13);
four.alphaTo(0,4,"",15);
three.alphaTo(0,4,"",17);
fifthteen.alphaTo(0,4,"",19);
thriteen.alphaTo(0,4,"",21);
five.alphaTo(0,4,"",23);
seven.alphaTo(0,4,"",25);
twelve.alphaTo(0,4,"",27);
six.alphaTo(0,4,"",29);

```

it should work from there…

---

<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:** [August 30, 2004, 9:18am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/9 "2004-08-30T09:18:05Z")

</div>

Hi idontknow07,

Thanks for your reaction, but it is not completely where i’m looking for. All the time there should only be one square at alpha 100. So when one square is at alpha 100 it should stay like that for a certain amount of second an then another should go to alpha 100 and the previous one should go back to alpha 50

---

<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:** [August 30, 2004, 9:25am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/10 "2004-08-30T09:25:27Z")

</div>

I think I could use a function like:

```auto
function fadeInOut (clip, alpha, speed){
	var aStart = clip._alpha ;
	var aTarget = alpha ;
	clip.onEnterFrame = function (){
		var dA = aTarget - this._alpha;
		this._alpha += dA / speed;
		if (Math.abs(dA) < 2){
			if (aTarget == alpha) {
				aTarget = aStart ;
			}
			else {
				this._alpha = aStart;
				delete this.onEnterFrame;
			}
		} 
	};
} ;

```

and call it with:

```auto
fadeInOut (square01, 100, 6)

```

But then I just have it for 1 square and it is needed, as I told before, for 24 squares in a random sequence

---

<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:** [August 30, 2004, 8:08pm UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/11 "2004-08-30T20:08:38Z")

</div>

I know its not what you were looking for. I was not going to create the whole effect for you but I was giving you a example.

> The alpha property for all squares is50. I would like the squares randomly fade to alpha 0 (stay on alpha 0 for approx. 8 seconds) and then fade back to alpha 50 again, while another one fade to alpha 0

try this:

```auto
one.alphaTo(0,4,"",1); //tells box one to fade to 0
one.alphaTo(50,4,"",8); // then tells the box one to fade back to 50, the 8 means it will start in 8 seconds

```

The four just means how many seconds you want the fading to complete. I hope that is what you looking for.

---

<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:** [August 31, 2004, 6:55am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/12 "2004-08-31T06:55:58Z")

</div>

Thanks idontknow07,

I got it working for one box but how can I make it that is’s going random (one at a time). As said before. I never worked with classes so everything is realy abracadabra to me

---

<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:** [August 31, 2004, 7:08am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/13 "2004-08-31T07:08:23Z")

</div>

I have it working, but the way how seems a little bit time-consuming

```auto
one.alphaTo(0,4,"",1); 
one.alphaTo(50,4,"",5);
ten.alphaTo(0,4,"",5);
ten.alphaTo(50,4,"",10);
fourteen.alphaTo(0,4,"",10);
fourteen.alphaTo(50,4,"",15);
// and that for all 15 squares

```

I realy don’t know how to handle this :h: Please help me out

---

<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:** [August 31, 2004, 7:40am UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/14 "2004-08-31T07:40:28Z")

</div>

I really dont know how to make it go random by itself other then the way I showed you. Im not that good with AS. I will figure out a way…

---

<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:** [August 31, 2004, 1:10pm UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/15 "2004-08-31T13:10:19Z")

</div>

I think I have the same problem. I know some of the basic things, but when it becomes to complicated I lose it all. Because I think that when one of the real big scripers would look to this question, it is maybe a script from 20 lines in total. I hope one of them will. When you comeup with something please let me know

cheers 🙂

---

<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:** [August 31, 2004, 7:54pm UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/16 "2004-08-31T19:54:32Z")

</div>

I went over to the MovieClip Tweening Prototypes forum [http://laco.wz.cz/forum/viewforum.php?f=1](http://laco.wz.cz/forum/viewforum.php?f=1) and ask the same question and laco said to store all the boxes in a array. heres the script laco wrote:

```auto

mc_arr = [mc1,mc2,mc3,mc4];
for (var i = 0; i < mc_arr.length; i++){
var mc = mc_arr*
var randomdelay = 8*Math.random()
mc.alphaTo(0,1,"linear",1)
mc.alphaTo(50,1,"linear",randomdelay+2)
}

```

---

<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:** [September 2, 2004, 1:20pm UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/17 "2004-09-02T13:20:59Z")

</div>

Hi idontknow07,

Thank you for the reply. This is indeed a start, but it still isn’t givin the effect I used saw in the example!

---

<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:** [September 2, 2004, 7:35pm UTC](https://forum.kirupa.com/t/fmx-random-alpha-fade-in-and-out/62555/18 "2004-09-02T19:35:00Z")

</div>

Well Im sorry my AS skills are limited. Maybe you can just do it the way I should you early…
