Hello,
I would greatly appreciate some assistance combining a snippit I have successfully used as the base of my navigation menu for sometime with another
snippit which creates great “dynamic menu buttons”
they both work great on there own.
However I can’t seem to “target” the dynamic buttons in order to have them
navigate to my “frame labels” and trigger functions using my switch/case code.
I am sure this is something super simple.
but I have always had issues targeting :jail:
I have pasted the code (fairly well commented) bellow
I have also attached an CS3 .fla to this posting.
any clues will again be appreciated.
thanks
//-----> Part 1
// I HAVE BEEN USING THIS FRAMEWORK FOR MY TIMELINE MENU I LIKE IT BUT NOW I WOULD LIKE TO COMBINE THIS
// AND THE DYNAMIC BUTTON ARRAY FOUND IN Part 2... I moved the btnClick listener inside of the changePage function but...
// still no love
stop();
function btnClick(e:MouseEvent){
gotoAndStop(e.currentTarget.name);
}
switch (currentLabel) {
case "INTERIORS" :
break;
case "STILL LIFE" :
break;
case "CONTACT" :
break;
case "BIO" :
break;
}
//-----> Part 2
// Here is the code from http://flashadvanced.com... this works great but I can't get it to work in conjunction with my switch/case
// Framework any advice or help with this would be much appreciated... thanks.
/*
********************************
* ActionScript 3 animated buttons
* http://flashadvanced.com
********************************
*/
//setting the frame rate to 60 fps
stage.frameRate = 60;
//creating an array for our items
var menuArray:Array = new Array("INTERIORS", "STILL LIFE",
"CONTACT", "BIO");
//spacing between the items
var spacing:Number = 5;
//we create a container for the items
var menuContainer:MovieClip = new MovieClip();
//adding the container to the stage
stage.addChild(menuContainer);
//we are looping through the menuArray
for(var i:int = 0; i < menuArray.length; i++){
//creating a new Button class instance
var btn:Button = new Button();
//placing the buttons on the stage
btn.x = 35 + (btn.width + spacing) * i;
btn.y = 35;
btn.itemNumber = i;
//we check the button status every frame
btn.addEventListener(Event.ENTER_FRAME, buttonStatus);
//we want to split the buttons array so we can get both "label" and "URL"
var splitArr:Array = menuArray*.split("|");
//the first element of the new array is the label of our button
btn.item_label.label.text = splitArr[0];
//the second is the URL address
btn.itemURL = splitArr[1];
//adding the buttons to the container
menuContainer.addChild(btn);
}
function mouseOverHandler(e:MouseEvent):void{
//if the cursor is over the button we set the "over" status to "true"
e.target.over = true;
}
function mouseOutHandler(e:MouseEvent):void{
//in the other case we set it to "false"
e.target.over = false;
}
function mouseClickHandler(e:MouseEvent):void{
var mc = e.target.parent;
//on click we navigate to the specified URL
if( mc.itemURL != undefined )
navigateToURL(new URLRequest(mc.itemURL));
else
changePage(mc.itemNumber);
}
function buttonStatus(e:Event):void{
var mc = e.target;
//we check the button status
if(mc.over == true)
//if the cursor is over the button we play the animation
mc.nextFrame();
else
//else we go to the previous frames
mc.prevFrame();
}
function changePage(num:int):void{
//we loop through the objects of our container
for( var i:int = 0; i < menuContainer.numChildren; i++ ){
var mc:MovieClip = MovieClip(menuContainer.getChildAt(i));
mc.over = false;
mc.clickArea.visible = true;
//adding event listeners
mc.addEventListener(MouseEvent.ROLL_OVER, mouseOverHandler);
mc.addEventListener(MouseEvent.ROLL_OUT, mouseOutHandler);
mc.addEventListener(MouseEvent.CLICK, mouseClickHandler);
mc.addEventListener(MouseEvent.CLICK, btnClick);
}
var mcSelected = MovieClip(menuContainer.getChildAt(num));
//when selected the button is not clickable
mcSelected.over = true;
mcSelected.clickArea.visible = false;
//we remove the event listeners from the selected item
mcSelected.removeEventListener(MouseEvent.ROLL_OVER, mouseOverHandler);
mcSelected.removeEventListener(MouseEvent.ROLL_OUT, mouseOutHandler);
mcSelected.removeEventListener(MouseEvent.CLICK, mouseClickHandler);
}
//we go to the homepage by default
changePage(0);