Tutorials
FILE CATEGORIES
Tutorials >> ActionScript Menu
DOWNLOAD SOURCE FILE FOR THIS TUTORIAL
Posted by framer
In this tutorial I show how to create a flash menu using nothing but Actionscript. Creating menus and other flash elements with only Actionscript makes updating, modifying, and experimenting extremely quick and easy.
//Set an Array to store the button names
//Push the button names into namesArray
//Set an Array to store the button urls
//Push the button urls into urlArray
//Set a for loop to loop 5 times. 5 referse to the number of buttons
//Create a movie clip named i on the next highest level.
//Create a movie clip named buttonBkg inside the button movie clip on the next highest level.
//Set the lineStyle for buttonBkg
//Begin the buttonBkg fill
//The lineTo parameters define the shape of the buttonBkg
//End the fill
//Set the text format
//Set myFormat parameters
//Create a new text field inside the button movie clip on the next highest level and define the x, y, width, and length.
//Place the name of the button into the textBox from the namesArray defined on line 7
//Set the text formate to the textBox
//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).
//This move the button over so all the buttons don�t lay on top of each other.
//Set the onRelease function to the buttonRelease function
//Set the buttonRelease function
//Set a varible named buttonName equal to the instance name of the current button being clicked on
//Set a varible named buttonIndex equal to the 6th character of the buttons instance name.
//This will return a number between 0 and 5. We will use this to pull the correct url from the urlArray
//get the url from the urlArray of the current button being clicked on. and target a blank window
Posted by framer
In this tutorial I show how to create a flash menu using nothing but Actionscript. Creating menus and other flash elements with only Actionscript makes updating, modifying, and experimenting extremely quick and easy.
//Set an Array to store the button names
- Code: Select all
var namesArray:Array = new Array();
//Push the button names into namesArray
- Code: Select all
namesArray.push("HOME", "ABOUT", "LICENSE", "SUBMIT", "CONTACT");
//Set an Array to store the button urls
- Code: Select all
var urlArray:Array = new Array();
//Push the button urls into urlArray
- Code: Select all
urlArray.push("http://www.flashframer.com",
"http://flashframer.com/about/",
"http://flashframer.com/license/",
"http://flashframer.com/submit/",
"http://flashframer.com/contact/");
//Set a for loop to loop 5 times. 5 referse to the number of buttons
- Code: Select all
for(i=0;i<5;i++){
//Create a movie clip named i on the next highest level.
- Code: Select all
this.createEmptyMovieClip("button"+i, this.getNextHighestDepth());
//Create a movie clip named buttonBkg inside the button movie clip on the next highest level.
- Code: Select all
this["button"+i].createEmptyMovieClip("buttonBkg", this["button"+i].getNextHighestDepth());
//Set the lineStyle for buttonBkg
- Code: Select all
this["button"+i].buttonBkg.lineStyle(0, 0�000000, 100, true, "none", "square", "round");
//Begin the buttonBkg fill
- Code: Select all
this["button"+i].buttonBkg.beginFill(0�999999);
//The lineTo parameters define the shape of the buttonBkg
- Code: Select all
this["button"+i].buttonBkg.lineTo(99, 0);
this["button"+i].buttonBkg.lineTo(99, 24);
this["button"+i].buttonBkg.lineTo(0, 24);
this["button"+i].buttonBkg.lineTo(0, 0);
//End the fill
- Code: Select all
this["button"+i].buttonBkg.endFill();
//Set the text format
- Code: Select all
<b>var myFormat:TextFormat = new TextFormat();</b>
//Set myFormat parameters
- Code: Select all
<b>myFormat.align = "center";
myFormat.font = "Tahoma";
myFormat.size = 13;
myFormat.color = 0xFFFFFF;
this["button"+i].textBox.embedFonts = false;
this["button"+i].textBox.selectable = false;
this["button"+i].textBox.antiAliasType = "advanced";</b>
//Create a new text field inside the button movie clip on the next highest level and define the x, y, width, and length.
- Code: Select all
this["button"+i].createTextField("textBox", this["button"+i].getNextHighestDepth(), 0, 2, this["button"+i]._width, this["button"+i]._height);
//Place the name of the button into the textBox from the namesArray defined on line 7
- Code: Select all
this["button"+i].textBox.text = namesArray[ i ];
//Set the text formate to the textBox
- Code: Select all
this["button"+i].textBox.setTextFormat(myFormat);
//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).
//This move the button over so all the buttons don�t lay on top of each other.
- Code: Select all
this["button"+i]._x = this["button"+(i-1)]._x + this["button"+i]._width + 5;
//Set the onRelease function to the buttonRelease function
- Code: Select all
this["button"+i].onRelease = buttonRelease;
}
//Set the buttonRelease function
- Code: Select all
function buttonRelease(){
//Set a varible named buttonName equal to the instance name of the current button being clicked on
- Code: Select all
var buttonName:String = this._name;
//Set a varible named buttonIndex equal to the 6th character of the buttons instance name.
//This will return a number between 0 and 5. We will use this to pull the correct url from the urlArray
- Code: Select all
var buttonIndex = buttonName.substr(6,1);
//get the url from the urlArray of the current button being clicked on. and target a blank window
- Code: Select all
getURL(urlArray[buttonIndex],"_blank");
}

Twitter