First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: David Doull | Website: http://www.artifactinteractive.com.au

Step 2: Let's get the ground scrolling.

The ground will scroll to the left of the screen, which is achieved by gradually reducing the x-coordinate of the ground movie clip.

We actually need two copies of the ground movie clip placed next to each other to achieve a smooth scrolling effect. The second copy is sometimes referred to as a buffer. This ensures that the ground always covers the stage. There is a little flash file below that demonstrates this:

press the play button to see it in action.


When the first copy of the ground has moved completely off the left of the stage both copies of the ground are reset back to their start positions.

Duplicate the ground

As shown above, we will need a second copy of the ground movieclip.
Which means we are going to duplicate the ground movie clip. So we will have two copies of the ground movie clip next to each other.

Instead of moving both of these movie clips to create our scrolling, what we will do is put them inside another movie clip (which we will call mainGround) and then we can move this parent movie clip instead of the two ground movie clips. In other words the mainGround movie clip will contain the two copies of the ground and we will just move mainGround instead of moving the two grounds individually.

The first thing we need to is to put the ground movie clip inside another new movie clip.

Select the ground movie clip and create a new movie clip (Insert > Convert to Symbol or F8). Give it the name mainGround and choose movie clip as the behaviour. Then in the instance panel set the instance name of this new movie clip to mainGround (as shown).

So what we now have is the ground movieclip inside of the mainGround movie clip. Why did we do that? Because we will now duplicate the ground movie clip within the mainGround movie clip. Then we will be able to move the two ground movie clips at once by just moving the parent mainGround movie clip. This will be less work for the flash player - as it only has to move one movie clip not two and hence will improve the speed of the scrolling. It seems like extra work for little pay off - but in building flash games the speed of the flash player is very important, so where-ever possible you should reduce the amount of code or movie clip manipulation that flash has to do.

We are now going to add in the clipEvent code for the mainGround movie clip. Select the mainGround movie clip and choose Window > Actions to open up the actions window then type the following.

Type the following code in the actions window.

onClipEvent (load) {

	ground.duplicateMovieClip("ground2", 100);
	ground2._x = ground._x+ground._width;
	groundStartx = this._x;


This code is contained within a load ClipEvent, so it will be run when the mainGround is first loaded.

The second line of the code makes a duplicate copy of the ground movie clip and gives it the name ground2 and a depth of 100.
The third line sets the x-position of ground2 to the x-position of the original ground plus the width of the ground. This has the effect of locating ground2 exactly to the right of the first ground movie clip.

The fourth line creates a new variable called groundStartx which is equal to the x-position of the the mainGround movie clip. The purpose of this variable is to store the start location of the mainGround movie clip - we will use this variable later.

The fifth line groundSpeed=10; just sets up a new variable called groundSpeed with a fixed value of 10. This will be the number of pixels the ground moves per frame.


» Level Intermediate

Added: 2001-05-01
Rating: 9 Votes: 232
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.