Flash Game Design  
 
     
Tutorials Articles
     
AddThis Social Bookmark Button  
 
Falling Star Text - Part 4) Actionscript   Part: 1 | 2 | 3 | 4
Step 17.
Now it's time to write some Actionscript! Create a 'script layer and click on the 1st frame in the timeline. Open up the Actions panel and enter the code shown below.

Line 1 - A variable containing the number of stars to be on the screen at once.

Line 2 - the maximum speed that the stars will move at and

Line 3 - the minimum speed.

Line 4 - The number of different colored stars

Line 5 - Maximum size to make the stars

Line 6 - Minimum size to make the stars.

 
Step 18.

Line 7 - 8: Next, we use a for loop to attach the 150 stars to the holder MC. We use the text "star" and combine it with 0-3, to attach one of the star MC's

Line 9 - 10: 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 260 (stage width ) for the x co-ordinate, and from 0 to 190 (stage height) for the y co-ordiante.

 
Step 19.

Line 11 - 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.

Line 12- We then randomly rezize the stars, by assigning a random number to the variable size.

Line 12-14: We then assign the star's width (mc._width) and height (star._height) with the size varaible.

 
Step 20.
Line 16 - 18 - this.onEnterFrame = function(){ } "is a function which will repeatedly run any code we put in between the braces {}, at the frame rate of the SWF file. We need to use it to repeatedly move the stars. Next, we create another for loop, to move all the stars at once. Earlier we created each star and name them star1, star2 etc, so now we need to tell each of them to move. We refer to the star as this["star"+j), with j being the current number in the loop. We then assign this["star"+j) to the variable mc because it's easier to write :)
 
Step 21.

Line 19-27: Next an if statement is used to check whether each star has reached the bottom of the text (y<140). If it hasn't we move the star down by adding the Y co-ordinate with the speed. If it has reached the bottom we reuse the star, randomizing its speed and position again (lines 22-24), with the code copied from the 1st block of code. You can also add the code to resize it if you like.

And that brings us to the end of this tutorial! Download FLA   Part: 1 | 2 | 3 | 4
 
   
 
   
 
Site Copyright © 2008 Nick DS. All rights reserved.