Graphics Programs Reference
In-Depth Information
Step 14: Enter the ActionScript
Open the Actions panel and add three lines to the ActionScript as shown.
1
2
3
function parallax()
{
if(forewater_mc._x <= -(forewater_mc._width/2)){
forewater_mc._x = 0;}
if(midwater_mc._x <= -(midwater_mc._width/2)){
midwater_mc._x = 0;}
if(backwater_mc._x <= -(backwater_mc._width/2)){
backwater_mc._x = 0;}
4
5
6
7
8
9
10
11
12
13
14
15
forewater_mc._x -= 6;
midwater_mc._x -= 4;
backwater_mc._x -= 2;
}
this.onEnterFrame = function()
{
parallax();
}
So what does this new code do? It checks to see whether the horizontal position ( _x )
for each instance is less than or equal to half of its width ( _width ). If it is, then half of
the instance has moved off the left edge of the Stage.
if(forewater_mc._x <= -(forewater_mc._width/2))
When this condition is true, the code resets the horizontal position of each instance to
zero. Setting a position to zero aligns it to the left edge of the Stage. This means that
the instance will snap back to its position aligned with the left edge of the Stage.
forewater_mc._x = 0;
These three new lines of code create the illusion of continuous movement on the
screen. Save and test the movie. You have completed parallax scrolling.
Step 15: Create a new layer
The last thing needed is a character to give the movement meaning and purpose.
Create a new layer above the middleground layer. Rename it to boat . If the Library is
 
Search WWH ::




Custom Search