Help with a Star-Field

Not exactly like the starfield in the tutorials on this site… because i dont really care about depth.

What i want is just a bunch of stars randomly blinking.

I have one star (MC) animated to blink.

I’m pretty sure i just have to use the duplicateMovieClip action… but i’m just not sure on the parameters.

Like i’d only want 25 - 50 stars at the most -n- such.

I’ve been trying a bunch of things now but i always get the “A script is this movie is causing Flash Player to run slowly” msg.

Any help would be appreciated thx =D

Ok… now my code is really really crappy and can be optimized a million times over, but its a point in the right direction I guess.

For some reason I could not get the setInterval function work correctly with this, I don’t see why I would have had problems, but I did, so that just made it worse, but this will be a point in the right direction at least.

Ok, I created a 3x3 white circle on the stage and made it a movie clip. Then I gave it the instance name “star” (no quotes).

Then I opened the actions panel for the movie clip and applied these actions.

onClipEvent (load) {
	blink = 1+Math.random()*10;
	interval = 0;
}
onClipEvent (enterFrame) {
	interval++;
	if (blink>=interval) {
		this._visible = true;
	} else {
		this._visible = false;
	}
	if (interval>=blink+(1+Math.random()*100)) {
		interval = 0;
	}
}

Now this creates the blinking effect so that you don’t have to do the frames way, because with the frames, since it isn’t random they will all blink at the same time. This is where setInterval was giving me problem… I am a bit off today obviously…lol.

Ok, Now I added these actions onto the keyframe.

_root.star._visible = false;
for (i=0; i<100; i++) {
	_root.star.duplicateMovieClip("star"+i, i);
	myStar = _root["star"+i];
	myStar._alpha = 10+Math.random()*60;
	myStar._x = Math.random()*Stage.width;
	myStar._y = Math.random()*Stage.height;
}

Now, this will first make your original clip invisible (we want that), then it will duplicate your clip 100 times (the i<100 part defines how much). Then then it random scatters each clip within your movies stage area (where the viewer can see) and randomly sets the alpha between 10 and 70.

Here ya go lsot… I’ll optimize these liens of code if you optimize my ai code…

DEAL?!

lol… j/k… GOod Job bro… Don’t see anything wrong wiht it… :slight_smile:

Peace

LOL, that setInterval thing is bugging me.

My code could be so much shorter with it…lol.

Bah… oh well, as long as it works.

If anyone else knows a better way (Ilyas…lol) then please be my guest and obliterate my code :beam:

nice… works great :stuck_out_tongue_winking_eye: thx a lot.

now if i wanted the blinking to go a lil slower would i set the interval higher???

edit: nm… interval thing just set the space between all of em flashin ;p

Well, I don’t see a very short way to use setInterval here, but here’s what I’ve come up with. Create a clip called star. On one layer of that clip, draw your star, then create another layer and add that code in it:

function blink(){
	clearInterval(this.interval);
	this._visible=1;
	this.interval=setInterval(this,"invisible",randomInterval);
}
function invisible(){
	clearInterval(this.interval);
	this._visible=0;
	this.interval=setInterval(this,"blink",randomInterval);
}
randomInterval=random(2000)+1000;
this.interval=setInterval(this,"invisible",randomInterval);

Not so short :-\

You could also create a new randomInterval each time a function is called.

Seems shorter than mine though Ilyas.

And definitely more complex :evil:

I forgot to say: you still need the duplication code on the main timeline :beam:

Ok, so it is pretty much the same, just my method is… easier to understand I guess.