2012-01-17 72 views
0

我想鏈接具有instace名test1的一個外部URL的影片剪輯(例如:http://www.google.com給鏈接到MovieClip外部URL在Flash ActionScript 3.0

我使用的主要有影片剪輯實例的菜單列表名稱爲「Primary_Menu」。在這個主要的影片剪輯裏有7個菜單(家庭,關於我們等等)。每個菜單都是影片剪輯並且有實例名稱。下面的代碼是爲了將它們鏈接到相應的框架而編寫的。但我需要給最後一個菜單的外部網址(test1)

Home_MC.logo_btn.addEventListener(MouseEvent.CLICK,ShowHome); 
    Home_MC.Primary_Menu.pmenu_btn1.addEventListener(MouseEvent.CLICK,ShowHome); 
    Home_MC.Primary_Menu.pmenu_btn2.addEventListener(MouseEvent.CLICK,ShowLocation); 
    Home_MC.Primary_Menu.pmenu_btn3.addEventListener(MouseEvent.CLICK,ShowMasterplan); 
    Home_MC.Primary_Menu.pmenu_btn4.addEventListener(MouseEvent.CLICK,ShowDesigner); 
    Home_MC.Primary_Menu.pmenu_btn5.addEventListener(MouseEvent.CLICK,ShowAmenities); 
    Home_MC.Primary_Menu.pmenu_btn6.addEventListener(MouseEvent.CLICK,ShowDevelopment); 
    Home_MC.Primary_Menu.pmenu_btn7.addEventListener(MouseEvent.CLICK,ShowContact); 
    Home_MC.Primary_Menu.pmenu_btn8.addEventListener(MouseEvent.CLICK,ShowLiving); 
    Home_MC.Primary_Menu.test1.addEventListener(MouseEvent.CLICK,need to got to url here); 

請建議!!

回答

1
for(var i:uint = 1;i< 10; i++) 
{ 
    Home_MC.Primary_Menu["pmenu_btn"+i].addEventListener(MouseEvent.CLICK, action); 
} 
function action(e:MouseEvent):void 
{ 
    switch(e.target.name){ 
     case "pmenu_btn9": 
       //do action 
        navigateToURL(new URLRequest("url link")); 
       break; 
       default: 
       break; 
    } 
} 

rename pmenu_btn9而不是test1。然後運行。

+0

不工作。請看我編輯的問題 – Sowmya 2012-01-17 12:20:01

+1

這應該工作。任何錯誤? – Diode 2012-01-17 12:38:19

+0

沒有不工作。已經有菜單,直到pmenu_btn9,所以我需要爲新菜單提供不同的即時名稱,並將其鏈接到外部網址。新鏈接也位於相同路徑(Home_MC.Primary_Menu.newlink) – Sowmya 2012-01-18 08:17:34