The ActionScript coding for "planet1", the planet object, is a bit different from that
last chunk of code. Instead of dealing with objects' reaction to player movement, the
planet1 script deals with setting the size of the planet, which, as we have seen above, is what
determines the simulated speed variables. Open the Actions box for the "planet1" instance
and enter the following code:
This time, in the (load) section, we set the starting size of the object (_height and _width)
as well as the starting location (_x and _y). We also introduce the "thrust" variable, which
will be an important part of the starfield objects as well. This is the forward speed of the
player. It begins as 0, and is influenced by keystrokes. At the end of the (load) section,
there is a very important piece of code, the "swapDepths" command. The planet is created on
its own layer, which is above the layer that holds player1, but it would ruin the effect
we're going for if the planet appeared in front of the target, so we have to switch the
depths of "planet1" and "player1". In the (enterFrame) section, we first see that as the
width of the planet object grows, so does the speed at which it seems to approach the
player ("approachSpeed"). After getting the correct value for "approachSpeed", we then
apply it to grow the size of the planet, making it seem to get closer. At the end of the
script are two keystroke handlers. Hitting the TAB key increases the thrust, hitting the CONTROL
key decreases it.