First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Ian Rose
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._height = 3;
 this._width = 3;

 this._x = 205;
 this._y = 105;

 thrust = 0;

 this.swapDepths( _root.player1 );

onClipEvent (enterFrame) 
 if (this._width <= 10)
  approachSpeed = (.02 * thrust);
 else if (this._width <=25)
  approachSpeed = (.04 * thrust);
  approachSpeed = (.06 * thrust);

 if (Key.isDown(Key.TAB)) 
  if (thrust <= 9)

 if (Key.isDown(Key.CONTROL)) 
  if (thrust >= -12)
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.

» Level Intermediate

Added: 2001-06-26
Rating: 6.89 Votes: 100
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.