First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
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.95 Votes: 99
(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: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.