Flash Game Design  
 
 
 
Tutorials Articles
     
AddThis Social Bookmark Button  
   
Step 12.
This is the final part of this Flash tutorial, where we will write the actionscript. This is the first part of the script, which will be explained below:
 
Code Explanation:

Line 1: The "pages" MC, containing the content, needs to be stopped from looping through each page.

Line 2: An X position start point is declared for the buttons in the variable xStart

Line 3: An Y position start point is declared for the buttons

Line 4: The individual button width is declared

Line 5: The individual button height is declared.

Step 13.
Code Explanation:

Line 6: A new XML object is created, called "menuXml".

Line 7 : We call the function "loadXml", which we are about to create, passing the string of the path of the xml file.

Line 8 : The loadXml function is created with a string parameter.

Line 9: White space in the XML file ignored with this command.

Line 10/11: When the XML file is loaded, the loadMapData function is called, which we are about to create. The file is loaded.

Step 14.
Code Explanation:

Line 12: The loadMapData function is created.

Line 13 : The XML is loaded as array, which we will loop through and use the "buttonName" attributes to create new instances of teh button MC. So, a FOR loop is created to loop though each childnode <menu buttonName>. The firstChild is <menu> from the XML file we create earlier.

Line 14: A temporary variable, "bn", is created to hold each "buttonName" attribute. So for the first iteration in the loop, bn will equal "About".

Line 15: A temporary variable, "b", is created to hold each button that's attached to the _root. The bn variable is used to give a unique instance name to each button.

Line 16: The "b" variable is used to set the X position of the button, which will be the same for each one.

Line 17: The Y position is set for each button, using the the increment "i" to multiply the height of the button (bHeight). This will make each button created be placed lowe down than the previous one.

Line 18: We use the "buttonName" attribute (bn) to assign the button text "b.txt". Remember we set the Var of the button MC to txt earlier?

Step 15.
Code Explanation:

Line 19: The "b" variable (holding the button instance name) is assigned an onPress function.

Line 20 : Remember when we gave each section a label ("about", "portfolio" etc). The "pages" MC is told to gotoAndStop at this.txt. We previously referenced is as b.txt, but since we are refering to the attribute in the onPress function, we use "this".

Line 21 : The text field, that we assign the Var "head", inside the pages MC, is set to this.txt. So that's 4 times we've used each "buttonName" attribute. :)

Line 22 : Each thumbnail is refered to using this["thumb"+i]. The For loop increments "i", for each button will be referenced.

Line 23 - 26 : We close all the braces with }

And here is the entire code:
 
Step 16.
Save the FLA and publish it in the same folder as the XML file. And that brings us to the end of this Flash tutorial :) Download FLA. You can create a sliding menu object by following the tutorial Dynamic Menu.
 
Part: 1 | 2 | 3
 
 
 
Site Copyright © 2008 Nick DS. All rights reserved.