Flash Game Design  
 
     
Tutorials Articles
     
Subscribe to Flash Tutorials  
 
Step 3.
This is the 2nd part of this Flash tutorial. Now it's time to write some Actionscript! First we'll write the part that will create the stars. So click on the 1st frame in the timeline, open up the Actions panel and enter the code shown below. var star is a variable containing the number of stars to be on the screen at once. As the name suggests, var maxSpeed is the maximum speed that the stars will move at and minSpeed the minimum speed. You can play around with the values later if you want.
 
Flash Tutorials
Move MC's with Keys
Dynamic Starfield
Shooting Bullets
 
 
Step 4.
Next, we use a for loop to attach the 150 stars. We use the identifier "star", that was assigned to the movie clip symbol at the start, to indicate what is to be attached. As each new star movie clip is create, it is temporarily assigned to the variable "mc" (var mc). Each star movie clip needs to be positioned randomly. To do this we assign it's x and y position, choosing a random number from 0 to 250 (stage width ) for the x co-ordinate, and from 0 to 190 (stage height) for the y co-ordiante.
 
Step 5.
Next, we're going to assign a random speed for the mc, giving each one a speed atrribute (mc.speed). The variables mxSpeed and minSpeed are used to create the random number. We then randomly rezize the stars, by assigning a random number to the variable size. We then assign the star's width (mc._width) and height (star._height) with the size varaible. So, by using random(2) the number will be from 0 - 2. With 0.6*(random(4), we are creating another random number to add on to it. The reason we are creating 2 random numbers is to generate lots of variations in size, but within a small range.
 
Step 6.
So now you should have the following block of code. Next go to Part 3 of this Flash tutorial
 
 
 
Flash Game Design | Photoshop & Flash Tutorials
 
Privacy Policy | Site Usage | Contact
Site Copyright © 2006 - 2009 Nick DS. All rights reserved.