Flash Game Design  
 
   
 
Tutorials Articles
   
       
 
 
Flash Snow Header - Part 3)  
Step 8.
This is the final of the tutorial, where we'll be writing the Actionscript to attach multiple instances of the snow flakes and make them move. Before we do that, name the top layer "script", click on the 1st frame, create a blank key frame (F7) and open up the Actions panel.
 
Step 9.

Line 1: Since we have 3 diferent type of snow flake, we need to set the quantity of each flake to be create. Each value is store in this array. There will be 150 of "snow0", 20, of "snow1", and 5 of "snow2".

Line 2 : We also need to set some properties for the snowflakes. These will be held in a object called sOb. As we create the snow flakes, "count" will increment by 1. min/maxSpeed hold the speeds, which will be randomly set. min/maxHeight, will be used to randomly set the heigh of the deformed circlular flake.

Line 3 : When we attach the snow flakes, they'll be stored in this array, which we can loop through to make each one move.

 
Step 10.

Line 4: Next, a For loop is created to go through the array holding the snow flake totals.

Line 5: Another for loop is used to attach each snow flake, using the value in the snowToal array.

Line 6: We use the value of "count" from the sOb object, combind with the text "snow" to give each snow flake a unique instance name. It'll be usique because "count" will be increased by 1 (line 14) everytime a flake mc is created. The count value is also used to place the MC on a unique "level". The instance of the MC is temporarily stored in the var "mc".

 

 

 
Step 11.

Line 8: using the temp var mc, the snow flak instance's height and width are romdly set using the min/max values

Line 10 - 12: The starting x&y positions and speed are also set.

Line 13: The flake instace is then put into the snowArray

Line 14: count is then increment by 1

 
Step 12.

Line 17: A function is created to move the snow flakes

Line 18: While two For loops were used to create the snow flake MCs, we only need to use a single loop to move them, becuase theyre all in a single array

Line 19: As snowArray is looped through, each flake is assigned temporarily to a var called mc.

Line 20 - 21: If the snow flake's Y position is below the stage height (the bottom of the header), it will move at the speed set.

Line 22 - 25: If it reaches the bottom, it's placed back to the top minus it's height, given a new speed and placed randomly on the X axis of the stage.

 
Step 13.

Line 29 - 30 : An onEnterFrame function is created which will execute moveSnow function repeatedly, at the frame rate (30) of the movie.

 
Step 14. Entire Code
 
 

And that's all the Actionscript that needs to be written to create the Flash Header!Download FLA

Part: 1 | 2 | 3
   
 
   
 
Site Copyright © 2006 - 2009 Nick DS. All rights reserved.