I have built a flash website. The problem I am having is that I can click home, and it goes there, I can click ABOUT US, and it goes there…but it wont work on any of the other pages. I am not sure what I am missing. Here is the code. Do I need an if/else or what?
//importing
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.Shape;
import flash.text.TextFormat;
import flash.text.TextField;
//Page Consistant Objects
var myHeader:HeaderMC = new HeaderMC;
var myNavigation:NavigationMC = new NavigationMC;
var myFooter:FooterMC = new FooterMC;
//above items are now visible
addChild (myHeader);
addChild (myNavigation);
addChild (myFooter);
//setting up header, Nav Bar, Buttons, and a floating footer
myNavigation.y = myHeader.y + 208;
myFooter.y = stage.stageHeight + 55;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//MENU
//menu buttons
var menuArray:Array = new Array();
//button names
var nameArray:Array = [“Home”,“About Us”,“Debt Free”,“Budget Resources”,“Survive Bankruptcy”,“Help Others”,“Contact Us”];
//START LOOP
//menu
for (var i:int = 0; i<6; i++){
//create the bg
var btnBg:Shape = new Shape();
//line style
btnBg.graphics.lineStyle(1, 0x0099ff, .5, true);
//begin fill
btnBg.graphics.beginFill(0x66cbff);
//draw bar
btnBg.graphics.drawRoundRect(0, 0, 150, 44, 10);
//end fill
btnBg.graphics.endFill();
//font object
var btnFont = new Verdana();
//text format
var btnFormat:TextFormat = new TextFormat();
//set font
btnFormat.font = btnFont.fontName;
//set properties
btnFormat.size = 15;
btnFormat.align = "center";
btnFormat.color = 0xffffff;
//new text field
var btnTxt:TextField = new TextField;
//set text format
btnTxt.defaultTextFormat = btnFormat;
//set properties
btnTxt.width = 150;
btnTxt.height = 65;
btnTxt.y = 13;
//create new instance loop
var myBtn:Sprite = new Sprite();
//give new button name
myBtn.name = nameArray*;
//set the sprite to act like button
myBtn.buttonMode = true;
//no listening
myBtn.mouseChildren = false;
//add buttons
menuArray.push(myBtn);
//add button to list
addChild(myBtn);
//position the button in horizontal line
myBtn.y = 212;
myBtn.x = 25 + (i*165);
//add background shape
myBtn.addChild(btnBg);
//add text field
myBtn.addChild(btnTxt);
//populate with text
btnTxt.text = myBtn.name;
//add event listeners
myBtn.addEventListener(MouseEvent.CLICK, btnHandler);
myBtn.addEventListener(MouseEvent.ROLL_OVER, btnHandler);
myBtn.addEventListener(MouseEvent.ROLL_OUT, btnHandler);
}
swapChildren (myBtn, myNavigation);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Index or Home Page
//content
var contentContainer:Sprite = new Sprite;
addChild(contentContainer);
contentContainer.x = 0;
contentContainer.y = myNavigation.y + myNavigation.height + 5;
//New Content Pages
var home:HomeMC = new HomeMC;
var about:AboutMC = new AboutMC;
var getStay:GetStayMC = new GetStayMC;
var budget:BudgetResMC = new BudgetResMC;
var bankrupt:BankruptMC = new BankruptMC;
var help:HelpMC = new HelpMC;
var contact:ContactMC = new ContactMC;
contentContainer.addChild(home);
// functions
function btnHandler(event:MouseEvent):void {
//check mouse click event
if (event.type == MouseEvent.CLICK) {
trace(event.target.name + " was clicked.");
//button
if (event.target.name == "Home") {
contentContainer.removeChildAt(0);
contentContainer.addChild(home);
}
//button
if (event.target.name == "About Us") {
contentContainer.removeChildAt(0);
contentContainer.addChild(about);
}
//button
if (event.target.name == "Get Out & Stay Out") {
contentContainer.removeChildAt(0);
contentContainer.addChild(getStay);
}
//button
if (event.target.name == "Budgeting & Resources") {
contentContainer.removeChildAt(0);
contentContainer.addChild(budget);
}
//button
if (event.target.name == "Surviving Bankruptcy") {
contentContainer.removeChildAt(0);
contentContainer.addChild(bankrupt)
}
//button
if (event.target.name == "Help Us Help Others") {
contentContainer.removeChildAt(0);
contentContainer.addChild(help);
}
//button
if (event.target.name == "Contact Us") {
contentContainer.removeChildAt(0);
contentContainer.addChild(contact);
}
//check to see if this is a roll over event
else if (event.type == MouseEvent.ROLL_OVER) {
//change the alpha of the button to create a roll over event
event.target.alpha = .7;
}
//check to see if this is a roll out event
else if (event.type == MouseEvent.ROLL_OUT) {
//change the alpha back to 100%
event.target.alpha = 1;
}
}
}