2010-03-10 185 views
0

我正在嘗試創建一個動態Flash導航菜單,該菜單將禁用將按鈕置於「命中」狀態的頁面按鈕,然後在您調用新頁面後激活它停用新的按鈕。動態Flash導航菜單

我知道這可以用電影剪輯和一些老學校gotoAndPlay /停止輕微的手,但我想在動作中做到這一點,所以它很好,乾淨,並可擴展其他項目。

我已經張貼了我的zip文件中嘗試在

http://www.webstudioproductions.com/navtry.zip

請重播回來幫忙

//編輯加成

我打電話此SWF從一個PHP包括功能。當我嘗試使用當前狀態下的swf按鈕時,除了停用的主頁和應該關閉的主頁,所有按鈕都可以讓用戶翻轉並激活。

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"); 
} 

回答

0

MovieClip是一個動態類,所以你可以給它額外的屬性。解決這個問題的一種方法是給每個菜單項一個isSelected布爾值。然後在父類中,將所有項存儲在數組中並控制所選值。

簡單的系統,我用的是這樣的

給每個菜單的isSelected布爾值
防止取消動畫如果isSelected ==真
存儲的所有菜單中的數組
按鈕創建一個掛線和每個菜單項的setOff函數
當按下菜單時,遍歷所有按鈕並更新選定狀態

function onButtonOut(e:MouseEvent):void 
{ 
    if(!isSelected) e.currentTarget.gotoAndPlay("out"); 
}