Flash Game Design  
 
   
 
Tutorials Articles
   
       
 
Step 8.
Now it's time to write the actionscript. Start off by entering the first 3 lines shonw below.
Code Explanation

Line 1 - The Content_MC needs to be told to stop, since it contains 5 frames.

Line 2 - A speed is set for the sliding "current" MC to move at.

Line 3 - An initial target position is set for the "current" MC to move to when the menu loads.

 
 
Step 9.
Now for the interesting part! :) The following code will go on the script layer. I'll explain each line below the code.
Code Explanation

Line 4 - Rather that write each button function individually, a for loop is created to loop through each button and assign an onPress function to it. The "i" in the loop will start off at 1 and increment by 1 (i++), while i is below 7 (i<7). If we had 10 buttons we would set this to i<11.

Line 5 - Each button is refered to using this["button"+i]. The For loop increments "i", so each button will be referenced. On this line a page number (pageNum) property is assigned to each button, using "i". Button1 will be assigned the pageNum "1", button2 "2" and so on.

Line 6 - An onPress function is assigned to each button.

Line 7 - When the any of the buttons is pressed the target variable is to the position of the button (this._y).

Line 8 - Content_Mc is told to go to the page number that was stored, on line 5, in the pageNum property.

 
 
 
Step 10.
Now for the interesting part! :) The following code will go on the script layer. I'll explain each line below the code.
Code Explanation

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

Line 12 - This is the code used to move the "current" MC to the "target" value, whenever a button is pressed.

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