Dynamic Menu using for loops
Create a new flash document.
Create a small rectangle approx 100 pixels and then convert it to a MovieClip called buttonMC.
Inside this movieclip create a dynamic text box (ensure it is the same length as the rectangle) and give it an instance name of labelText.
Return to scene 1 and delete the movieclip from the stage.
Open the library, select the movieclip and right click selecting properties from the list. Change the settings to match below:

Press ok.
Create a new layer on the main timeline and open the actionspanel. Type tyhe folowing code:
var mc:MovieClip = new MovieClip(); addChild(mc); var myText:TextField = new TextField(); myText.text = "No button has been pressed"; myText.width = 300; mc.addChild(myText);
The first two lines create a blank movieclip and attaches this to the stage. Then a textFiled called myText is created and text is added to this along with its width before being added to the stage inside the blank movieclip that has been created.
Next add the following code:
for(var i:Number = 0; i<5; i++){
var button:buttonMC = new buttonMC();
button.buttonMode=true;
button.information="Page"+i;
button.labelText.text = "Page"+i;
button.x=30;
button.y=50*i+70;
button.addEventListener(MouseEvent.CLICK, pressedButton);
addChild(button);
}
function pressedButton(evt:MouseEvent):void{
myText.text = String(evt.target.information);
}
The first line is the for loop and ios set to iterate 5 times through the loop. Next a new variable is created for the buttonMC and as this is a movieclip the next line sets this to behave like a button. The next line sets the information relating to this button in this case the first button will be Page0 as i = 0. If you wanted it to be page 1 you woulkd have to alter the varaible to 1 instead of 0. The next line will add the text to the dynamic text box you created inside the movieclip. The following two lines position it and giving it the x and y value. Then we add an event listener to the button which will call the pressedButton function once the mouse button is clicked. Finally it is added to stage.
The function changed the text on the screen to display the button information for which button has been clicked.
Control / Test Movie.
Excercise
Expand the code so that when the first button is clicked it will take you to frame 5, the second button frame 10 etc.. You will need to put some text on this page to help identify that it works.
