Random Blips

Hi,

I have a background image of which I’d like parts blinking randomly. You know, you’ve probably seen it a thousand times. A background image, and some masked white blips go over parts of the background. That is what I’d like. But I want them to blink randomly, with some time in between … How should I do this ?

voet -

you could do something like the following:


// start random flashing of myMovieClip_mc
// set minimum and maximum interval values in seconds
tMin = 20;
tMax = 400;

function move() {
	myMovieClip_mc.gotoAndPlay(2);
	
	//reset random interval
	clearInterval(moveInt);
	t = Math.round((Math.random()*(tMax - tMin)) + tMin)*1000;
	moveInt = setInterval(move, t);
	
}

//set initial interval
moveInt = setInterval(move, 20000);

That looks good :slight_smile: Thanks, I never used random and setInterval before =)

You could also create several different movieclips and name them sequentially (mc1, mc2, mc3…). Then use an attachMovie method to load them at random in a transparent placeholder on your stage.

This script is attached to the placeholder movieclip:

onClipEvent(enterFrame){
_root.placeholder.attachMovie(“mc” + random(5), “mcx”, 1);
}

Where random(5) says shoose any one of 5 movieclips named mc1 to mc5 and mcx is the new name of the loaded movieclip (this can be anything, it doesn’t matter unless you are reusing the attached movieclip in another script). Create blank movieclips to load as your intervals. The only disadvatage of this is that you will get a new blip for each of your 12 (or whatever) frames per second. The advantage is that your blips will vary, rather than playing the same blip again and again.

You could probably create a function that loads different movieclips at random and then uses liam’s script to create better intervals.

Thanks guys :slight_smile: You both helped me really well =) I used this: my movieclips were named mc1, mc2 … mc5, invisible on the first frame and the fading animation on the frames after that and a stop action on the first frame so it won’t keep playing and it stops at invisible state to be called again:

[AS]
tMin = 5;
tMax = 10;
function randomblips() {
randommc = “mc”+Math.round(Math.random()5);
tellTarget(randommc){
gotoAndPlay(2);
}
clearInterval(moveInt);
t = Math.round((Math.random()
(tMax-tMin))+tMin)*1000;
moveInt = setInterval(randomblips, t);
}
//set initial interval
moveInt = setInterval(randomblips, 1000);
[/AS]

[EDIT] I had to use tellTarget because randommc.gotoAndPlay(2); doesn’t work. Does anyone know why ?

You could use[AS]tMin = 5;
tMax = 10;
function randomblips() {
randommc = Math.floor(Math.random()5)+1;
_root[“mc”+randommc].gotoAndPlay(2);
clearInterval(moveInt);
t = Math.round((Math.random()
(tMax-tMin))+tMin)*1000;
moveInt = setInterval(randomblips, t);
}
moveInt = setInterval(randomblips, 1000)[/AS]

Thanks claudio :slight_smile: I knew it was something like that, just couldn’t remember :stuck_out_tongue:

welcome Voetsjoeba :slight_smile: