Graphics Programs Reference
In-Depth Information
each instance. Select the background instance. Go to the Properties panel and enter
background_mc in the instance name box. Select the middleground instance. Go to
the Properties panel and enter middleground_mc in the instance name box. Select
the foreground instance. Go to the Properties panel and enter foreground_mc in the
instance name box (Figure 4.16).
Figure 4.16 Instance name for the foreground movie clip
Step 3: Create a new layer
Add a layer above the foreground layer and label it actions . Open the Actions panel.
If the Actions panel is not open, choose Window > Actions.
Step 4: Enter the ActionScript
Enter the ActionScript as shown. You are creating a function called parallax . This
function animates each instance's position on the screen. For this exercise, the anima-
tion will change based on user input. The external event is the position of the cursor on
the Stage. The Flash player keeps track of the cursor's position using two properties:
_xmouse and _ymouse . The horizontal position is stored in _xmouse ; the vertical position
is stored in _ymouse .
1
2
3
4
5
6
7
function parallax(layer, speed)
{
if(_xmouse > Stage.width/2){
layer._x -= speed;
}else{
layer._x += speed;
}
This script tests to see where the cursor is in relationship to the Stage width. The Stage
has a property called width . Dividing it by two gives you the Stage's horizontal center.
Depending on where the cursor is (to the left or to the right of center Stage), the movie
Search WWH ::




Custom Search