Flash Game Design  
 
   
 
Tutorials Articles
   
       
 
 
Step 20.
This is the final part the Flash tutorial to create animated floating bubbles, where we'll be writing the Actionscript. Name the first layer "script", click on the first frame and open up the Actions panel.
 
Step 21.
Enter the code shown below, which will be explained underneath.
 

Line 1: the total number of bubbles that will be created

Line 2: a variable use when attaching movieclips, to give each new one a "level" to be placed on.

Line 3: An array which will hold the time that each ubble will start animating along the path.

Line 4: A variable used when each bubble shall start

 
Step 22.

Line 5: As it's name suggests, this function will create an interval between the starts times of each bubble.

Line 6: A loop is created to make as many intervals as there are bubbles, using the variable "total"

Line 7: Each time the loop iterates an interval is added to the releaseTimes array. Flash reads time in milliseconds, so 500 will equal 0.5 seconds. You can adjust these values depending on how long you want the interval between each bubble starting to animate.

 
Step 23.

Line 10: A createBubble function is created.

Line 11: since we created 3 paths a random variable (0-2) is created, so one of the paths is randomly selcted.

Line 12: the random path is then attached to the stage, and then assigned to the random variable "float"

Line 13: a buble is then attached to the emptyClip MC in the path mc.

Line 14: The float is positioned randomly on the X axis

Line 15: And outside the visible area on the Y axis

Line 16 - 17: The width, height and opacity are set randomly

Line 18: The level variable is increased by 1.

 
Step 24.

Line 20: The createInterval function is called once.

Line 21: A nextTime variable is declared, using the first value in the releaseTime array.

Line 22: An onEnterFrame function is created which will execute any code inbetween the braces {} repedly, at the frame rate of the movie.

Line 23: A temporary variable is created and assigned the current time

Line 24: An IF statement is used to check if the time is over nextTime

Line 25: If it is a new bubble is created

Line 26 - 27 - incr is increased by one so that the next value in the releaseTIme array is now checked.

 
Step 25.
Here is the entire code
 
Next add a background to go behind the floating bubbles, bringing us to the end of this Flash tutorial! Download FLA Part: 1 | 2 | 3
 
   
 
   
 
Site Copyright © 2006 - 2009 Nick DS. All rights reserved.