Article

Home » Design and Layout » Flash Tutorials » Flash Script - Star Field Effect

About the Author

SitePoint

View all articles by SitePoint...

Flash Script - Star Field Effect

By SitePoint

July 24th, 2003

Reader Rating: 7

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!

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: