Flash Script – Star Field Effect

By Georgina Laidlaw

Creating a starfield effect is easy! To begin, download the sample files here.

1. Create a small star shape, and convert it to a movie clip. Give it an instance name of star.

2. Extend the existing layer by three frames. Then, create a new layer above the existing layer, and create three blank frames in this layer.

3. In the first layer, insert the actions:

numstars = 100; 
speed = 5;
star_field = new Array (numstars);
//x is x axis, y is y axis, speed is speed of star
function star(x,y,z)
 this.x = x;
 this.y = y;
 this.speed = speed;
for (i=0;i<numstars;i++)
star_field[i] = new star(random(300),random(200),random(speed)+1);
duplicateMovieClip ("star", "star_" add i, i+10);

4. In the second key frame, insert this action:

for (i=0;i<numstars;i++) 
star_field[i].x+= star_field[i].speed;
if (star_field[i].x>300) { star_field[i].x = 0; }
setProperty ("star_" add i , _x , star_field[i].x )
setProperty ("star_" add i , _y , star_field[i].y )
setProperty ("star_" add i , _alpha , star_field[i].speed*40 )

5. Finally, in the third, insert:

gotoAndPlay (2);

That’s it! Test the movie!

No Reader comments


Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Instant Website Review

Use Woorank to analyze and optimize your website to improve your website to improve your ranking!

Run a review to see how your site can improve across 70+ metrics!

Get the latest in Front-end, once a week, for free.