Game element: Scrolling background
 
Description
Many games require a moving or scrolling background. A scrolling background works by moving a tiled pattern beneath a mask to give the appearance of an infinite pan.
 

 
This sample demonstrates how you can create a randomly generated star field that is tiled so that it loops both vertically and horizontally.
 
Key features and ActionScript elements
Mask layers, draggable movie clips, Math object, duplicateMovieClip, conditions (if...), logical NOT(!)
 
Instructions
Click Generate Star Field to begin. Each time you click it, a new field is generated. Manipulate the sliders to set the star field in motion. Notice how the scrolling background repeats seamlessly. Click Toggle Edge Lines to hide the dotted lines that mark the edges of the tiles.
 

 
The source file for this movie (Scrolling_starfield.fla) can be found in the Flash MX/Samples folder.