Dynamic Flash Navigation Menu
I am trying to create a Dynamic flash Navigation Menu which will disable the button of the page you are on leaving the button in the "hit" state and then active it once you have called for a new page and deactivate the new button.
I know this can be done with movie clips and some old school gotoAndPlay/Stop slight of hand but I would like to do this in actionscript so its nice, clean, and scalable for other projects.
I have posted my try in a zip file at
http://www.webstudioproductions.com/navtry.zip
Please replay back with any help
//Edited Addition
I am calling this swf in from a php include function. When I tried the swf in its current state all buttons but the home page where deactivate开发者_如何学JAVAd and home which should have been turned off let a user roll over and become active.
stop();
//get page string
var pageURL:String=ExternalInterface.call('window.location.href.toString');
//set up website pages
var homeURL:String=('http://www.webstudioproductions.com/index.html');
var servicesURL:String=('http://www.webstudioproductions.com/services.html');
var portfolioURL:String=('http://www.webstudioproductions.com/portfolio.html');
var associatesURL:String=('http://www.webstudioproductions.com/associates.html');
var contactusURL:String=('http://www.webstudioproductions.com/contactus.html');
// show rollover state of pageURL
function pageLoad():void {
if(pageURL==homeURL) {
nav.nav_home.gotoAndPlay("hit");
}else if(pageURL==servicesURL){
nav.nav_service.gotoAndPlay("hit");
}else if(pageURL==portfolioURL){
nav.nav_portfolio.gotoAndPlay("hit");
}else if(pageURL==associatesURL){
nav.nav_associates.gotoAndPlay("hit");
}else if(pageURL==contactusURL){
nav.nav_contactus.gotoAndPlay("hit");
}else{
gotoAndStop(1);
}
}
pageLoad();
/* main nav */
nav.nav_home.buttonMode = true;
nav.nav_home.addEventListener(MouseEvent.ROLL_OVER, onButtonOver);
nav.nav_home.addEventListener(MouseEvent.ROLL_OUT, onButtonOut);
nav.nav_home.addEventListener(MouseEvent.CLICK, nav_homeClick);
nav.nav_service.buttonMode = true;
nav.nav_service.addEventListener(MouseEvent.ROLL_OVER, onButtonOver);
nav.nav_service.addEventListener(MouseEvent.ROLL_OUT, onButtonOut);
nav.nav_service.addEventListener(MouseEvent.CLICK, nav_serviceClick);
nav.nav_portfolio.buttonMode = true;
nav.nav_portfolio.addEventListener(MouseEvent.ROLL_OVER, onButtonOver);
nav.nav_portfolio.addEventListener(MouseEvent.ROLL_OUT, onButtonOut);
nav.nav_portfolio.addEventListener(MouseEvent.CLICK, nav_portfolioClick);
nav.nav_associates.buttonMode = true;
nav.nav_associates.addEventListener(MouseEvent.ROLL_OVER, onButtonOver);
nav.nav_associates.addEventListener(MouseEvent.ROLL_OUT, onButtonOut);
nav.nav_associates.addEventListener(MouseEvent.CLICK, nav_associatesClick);
nav.nav_contactus.buttonMode = true;
nav.nav_contactus.addEventListener(MouseEvent.ROLL_OVER, onButtonOver);
nav.nav_contactus.addEventListener(MouseEvent.ROLL_OUT, onButtonOut);
nav.nav_contactus.addEventListener(MouseEvent.CLICK, nav_contactusClick);
function onButtonOver(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay("over");
}
function onButtonOut(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay("out");
}
/* main nav */
function nav_homeClick(e:MouseEvent):void
{
var nav_homeURL:URLRequest = new URLRequest ("http://www.webstudioproductions.com/index.html");
navigateToURL(nav_homeURL, "_parent");
}
function nav_serviceClick(e:MouseEvent):void
{
var nav_serviceURL:URLRequest = new URLRequest ("http://www.webstudioproductions.com/services.html");
navigateToURL(nav_serviceURL, "_parent");
}
function nav_portfolioClick(e:MouseEvent):void
{
var nav_portfolioURL:URLRequest = new URLRequest ("http://www.webstudioproductions.com/portfolio.html");
navigateToURL(nav_portfolioURL, "_parent");
}
function nav_associatesClick(e:MouseEvent):void
{
var nav_associatesURL:URLRequest = new URLRequest ("http://www.webstudioproductions.com/associates.html");
navigateToURL(nav_associatesURL, "_parent");
}
function nav_contactusClick(e:MouseEvent):void
{
var nav_contactusURL:URLRequest = new URLRequest ("http://www.webstudioproductions.com/contactus.html");
navigateToURL(nav_contactusURL, "_parent");
}
MovieClip is a dynamic class so you can give it extra properties. One way to get around this is to give each menu item an isSelected Boolean value. Then in the parent class you store all items in an array and control the selected value.
The simple system I use goes something like this
give each menu an isSelected Boolean value
prevent the deselect animation if isSelected == true
store all menu buttons in an array
create a setOn and setOff function for each menu item
when menu is pressed, loop through all buttons and update selected states
function onButtonOut(e:MouseEvent):void
{
if(!isSelected) e.currentTarget.gotoAndPlay("out");
}
精彩评论