Graphics Programs Reference
In-Depth Information
Step 7: Enter the ActionScript
Add to the ActionScript as shown. This script changes the walker_mc instance to walk
in the correct direction. Setting the _xscale property to -100 flips the movie clip hori-
zontally. Setting it to 100 puts it back to the original dimensions (Figure 4.18).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function parallax(layer, speed)
{
if(_xmouse > Stage.width/2){
layer._x -= speed;
walker_mc._xscale = 100;
}else{
layer._x += speed;
walker_mc._xscale = -100;
}
if(layer._x <= 0){
layer._x = layer._x + layer._width/2;
}else if(layer._x >= layer._width/2){
layer._x = layer._x - layer._width/2;
}
}
foreground_mc.onEnterFrame = function(){parallax(this,10);}
middleground_mc.onEnterFrame= function(){parallax(this,5);}
background_mc.onEnterFrame = function(){parallax(this,2);}
_xscale = 100
_xscale = -100
Figure 4.18 Positive and negative horizontal scales
 
Search WWH ::




Custom Search