Graphics Programs Reference
In-Depth Information
The code calls the
parallax
function every time it enters the frame. It also passes two
parameters into the function (
this,10
). Parameters are additional bits of information
that a function may need in order to execute the code correctly. For this example,
this
refers to the instance name of the movie clip calling the function. The number
10
refers
to the speed at which the instance will move.
foreground_mc.onEnterFrame = function(){parallax(this,10);}
The parallax function has two parameters associated with it:
layer
and
speed
. When
the function is called from the movie clip, the instance name stored in
this
is passed
into the function's parameter
layer
. The numeric value (10) is passed into the func-
tion's parameter
speed
.
function parallax(layer, speed)
The function uses the information passed into its parameters to move the correct
instance at the defined speed. This type of programming makes the code reusable and
allows you to revise or update it more efficiently.
Step 6: Name the instances
Select the
walker
instance. Go to the Properties panel and enter
walker_mc
in the
instance name box (Figure 4.17).
Figure 4.17
Instance name for the walk cycle movie clip
The walk cycle needs to reflect the movement based on the cursor's position. We could
create a new movie clip with the artwork flipped horizontally, but that would add to the
final file size. A better way to control this is through the
MovieClip
_xscale
property.
This property allows you to scale the dimensions of a movie clip through ActionScript.
The
_xscale
property scales the horizontal dimensions; the
_yscale
property scales
the vertical dimensions.
Search WWH ::
Custom Search