Create a Flash Menu using only Actionscript.

in Tutorials |
Create a Flash Menu using only Actionscript.

This tutorial covers how to create a Flash Menu using nothing but Actionscript. Each buttons background, border, text, and click through will all be created using only Actonscript. You can quickly modify the total number of buttons, size, color, spacing, click through, and position using a completely code based menu.

For step-by-step instructions read the commented lines in the code below.

  1. //Flash Framer Actionscript Menu
  2. //www.flashframer.com
  3.  
  4. //Set an Array to store the button names
  5. var namesArray:Array = new Array();
  6. //Push the button names into namesArray
  7. namesArray.push("HOME", "ABOUT", "LICENSE", "SUBMIT", "CONTACT");
  8.  
  9. //Set an Array to store the button urls
  10. var urlArray:Array = new Array();
  11. //Push the button urls into urlArray
  12. urlArray.push("http://www.flashframer.com",
  13. "http://flashframer.com/about/",
  14. "http://flashframer.com/license/",
  15. "http://flashframer.com/submit/",
  16. "http://flashframer.com/contact/");
  17.  
  18. //Set a for loop to loop 5 times. 5 referse to the number of buttons
  19. for(i=0;i<5;i++){
  20. //Create a movie clip named i on the next highest level.
  21. this.createEmptyMovieClip("button"+i, this.getNextHighestDepth());
  22. //Create a movie clip named buttonBkg inside the button movie clip on the next highest level.
  23. this["button"+i].createEmptyMovieClip("buttonBkg", this["button"+i].getNextHighestDepth());
  24. //Set the lineStyle for buttonBkg
  25. this["button"+i].buttonBkg.lineStyle(0, 0x000000, 100, true, "none", "square", "round");
  26. //Begin the buttonBkg fill
  27. this["button"+i].buttonBkg.beginFill(0x999999);
  28. //The lineTo parameters define the shape of the buttonBkg
  29. this["button"+i].buttonBkg.lineTo(99, 0);
  30. this["button"+i].buttonBkg.lineTo(99, 24);
  31. this["button"+i].buttonBkg.lineTo(0, 24);
  32. this["button"+i].buttonBkg.lineTo(0, 0);
  33. //End the fill
  34. this["button"+i].buttonBkg.endFill();
  35.  
  36. //Set the text formate
  37. var myFormat:TextFormat = new TextFormat();
  38. //Set myFormat parameters
  39. myFormat.align = "center";
  40. myFormat.font = "Tahoma";
  41. myFormat.size = 13;
  42. myFormat.color = 0xFFFFFF;
  43. this["button"+i].textBox.embedFonts = false;
  44. this["button"+i].textBox.selectable = false;
  45. this["button"+i].textBox.antiAliasType = "advanced";
  46. //Create a new text field inside the button movie clip on the next highest level and define the x, y, width, and length.
  47. this["button"+i].createTextField("textBox", this["button"+i].getNextHighestDepth(), 0, 2, this["button"+i]._width, this["button"+i]._height);
  48. //Place the name of the button into the textBox from the namesArray defined on line 7
  49. this["button"+i].textBox.text = namesArray[i];
  50. //Set the text formate to the textBox
  51. this["button"+i].textBox.setTextFormat(myFormat);
  52. //Set the X position of the button equal to the last button plus the width of this button plus 5 (5 is the space between each button).
  53. //This move the button over so all the buttons don't lay on top of each other.
  54. this["button"+i]._x = this["button"+(i-1)]._x + this["button"+i]._width + 5;
  55. //Set the onRelease function to the buttonRelease function
  56. this["button"+i].onRelease = buttonRelease;
  57. }
  58.  
  59. //Set the buttonRelease function
  60. function buttonRelease(){
  61. //Set a varible named buttonName equal to the instance name of the current button being clicked on
  62. var buttonName:String = this._name;
  63. //Set a varible named buttonIndex equal to the 6th character of the buttons instance name.
  64. //This will return a number between 0 and 5. We will use this to pull the correct url from the urlArray
  65. var buttonIndex = buttonName.substr(6,1);
  66. //get the url from the urlArray of the current button being clicked on. and target a blank window
  67. getURL(urlArray[buttonIndex],"_blank");
  68. }

Leave a Reply

© Flash Framer 2008
Entries RSS Comments RSS Log in