Graphics Programs Reference
In-Depth Information
Step 12: Enter the ActionScript
Enter the ActionScript as shown. Let's deconstruct the script. First you are creating
a function called parallax . This function animates each instance's position on the
screen. Each instance name is referenced, and the horizontal position ( _x ) for each
is decreased a specific amount ( -= ). This will move each instance to the left. The
onEnterFrame script continuously calls to the parallax function, creating constant
movement on the screen.
1
2
3
4
5
6
7
8
9
function parallax()
{
forewater_mc._x -= 6;
midwater_mc._x -= 4;
backwater_mc._x -= 2;
}
this.onEnterFrame = function()
{
parallax();
}
Step 13: Save and test movie
Save the Flash file and test it. Choose Control > Test Movie. Each layer of water is mov-
ing at a different speed, but there is a problem. Each layer keeps moving off the screen
(Figure 4.12). To solve this, you need to add a condition to your code.
Figure 4.12 Each instance moves at a different speed but keeps going.
Search WWH ::




Custom Search