[FMX]Random alpha fade in and out

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

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

Hi
You could use something like the moviclip tweening class or the one from 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

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…?

Hi Findal

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

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
(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.

:slight_smile:
Findal

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 ?

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

#include "lmc_tween_as1.as"

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


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…

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

I think I could use a function like:

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:

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

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:

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.

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

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

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

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…

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 :slight_smile:

I went over to the MovieClip Tweening Prototypes forum 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:


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)
}

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!

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