Flash Game Design  
 
     
Tutorials Articles
     
AddThis Social Bookmark Button  
 
Advanced Drop Down Menu  
4) Writing the Functionality of the Buttons
Step 12.
In the previous part the buttons were added using actionscript. In this final part we'll be adding functionality to the buttons.

Line 33 - A closeMenu() function created which will be called when a subButton is pressed, or if the drop down menu is open and the main button is pressed again.

Line 34 - 36 - The sub button MCs are then looped through and made invisible.

Line 37 - 38 - They're then positioned back to the start, ready to be scrolled down again.

Line 40 - menuOpen is then set to false

 
Step 13.

Line 42 - Next an onPress function is created for the main button.

Line 43 - menuOpen is checked to see if it's false (!menuOpen)

Line 44 - If is false, that means to menu is closed, so the current time (getTimer) is assigned to 'theTime'. This variable will then be used as an interval between each button scrolling.

Line 45 - Now that the button has been pressed, while it's closed, menuOpen is set to true.

Line 46 - 48 - A FOR loop is then used to make each button visible.

Line 49 - 51 - If menuOpen is true (else) and the main button MC is pressed the menu is currently open, so the closeMenu() function is called.

 
Step 14.

Line 53 - 54 - Next a function is created to scroll the buttons if the menu is open

Line 55 - 56 - The buttons are looped through again, and b is assigned to hole the current button in the loop.

Line 57 - Back over at line 26, an interval was assigned to each subButton. This is now added on to the time recorded at line 54, when the mainButton was pressed, and checked to see if it's lower than the current time (<getTimer).

Line 58 - This is the code used to move the b (subButton) to b's "target" value minus b's current X position divided by the scroll speed

 
Step 15.

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

Line 64- The scrollButtons function can be called repetedly, since there's an IF statement checking to see if the menu is open.

 
Step 16. Entire Code
 
 
And that's all the Actionscript that needs to be written to create the drop down menu. Download FLA
Part: 1 | 2 | 3 | 4 |
   
 
   
 
Site Copyright © 2008 Nick DS. All rights reserved.