2010-12-11 7 views
0

У меня есть 6 кнопок на одном слое, все с зависанием над эффектами и сортировкой. Я назначил каждое одно имя экземпляра, и попытался сделать ActionScript связать каждое изображение Google, однако следующий код не не работает:Ссылки на кнопки, не работающие в actionscript - flash cs4, AS3

function init():void { 
    blogButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    homeButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    portfolioButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    aboutButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    signButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    contactButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
} 

function onActionPerformed(e:MouseEvent):void { 
    switch(e.currentTarget) { 
     case homeButton: navigateToURL(new URLRequest("http://google.com"), "_blank"); break; 
     case blogButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case portfolioButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case aboutButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case signButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case contactButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
    } 
} 

Нет ошибок, или компиляции ошибок, просто не пойти куда-нибудь.

EDIT Код был слегка изменен, однако до сих пор не функционирует, я сделал ссылку, чтобы загрузить самый последний файл FLA: http://danlamanna.com/misc/navigation.fla

+0

если вы ставите трассировку (e.currentTarget), поскольку первая строка метода onActionPerformed() выводит то, что вы ожидаете? – greggreg

+0

Нет, однако я никогда не делал вывод со вспышкой раньше, поэтому я должен ожидать, что Google появится в окне фильма или откроет мой браузер по умолчанию? В любом случае это не так. –

+0

хорошо, если он не генерирует какой-либо выход, когда вы нажимаете кнопки, тогда ваша проблема перед вызовом метода. Вы попробовали инструкцию trace? Он выводится на панель вывода во флэш-памяти. В начале вашего приложения попробуйте кодирование: trace («я полезен для отладки») – greggreg

ответ

0

Если вы планируете оставить свой код на шкале времени, и ваши слушатели только должны быть установлены во время выполнения, то вам не нужно обернуть слушателя экземпляра в функции, как у вас есть сейчас. Просто их функции и поставить их выше onActionPerformed функции, как так:

blogButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
homeButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
portfolioButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
aboutButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
signButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
contactButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 

function onActionPerformed(e:MouseEvent):void 
{ 
    switch(e.currentTarget) 
    { 
     case homeButton: navigateToURL(new URLRequest("http://google.com"), "_blank"); break; 
     case blogButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case portfolioButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case aboutButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case signButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case contactButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 

    } 

} 

Если вам нужно динамически добавлять и удалять слушателей в более поздние времена, попробовать что-то вроде этого:

addListeners(); 

function addListeners():void 
{ 
    blogButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    homeButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    portfolioButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    aboutButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    signButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
    contactButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
} 

function removeListeners():void 
{ 
    blogButton.removeEventListener(MouseEvent.CLICK,onActionPerformed); 
    homeButton.removeEventListener(MouseEvent.CLICK,onActionPerformed); 
    portfolioButton.removeEventListener(MouseEvent.CLICK,onActionPerformed); 
    aboutButton.removeEventListener(MouseEvent.CLICK,onActionPerformed); 
    signButton.removeEventListener(MouseEvent.CLICK,onActionPerformed); 
    contactButton.removeEventListener(MouseEvent.CLICK,onActionPerformed); 
} 

function onActionPerformed(e:MouseEvent):void 
{ 
    switch(e.currentTarget) 
    { 
     case homeButton: navigateToURL(new URLRequest("http://google.com"), "_blank"); break; 
     case blogButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case portfolioButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case aboutButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case signButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
     case contactButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
    } 
} 
0

Вы должны добавить вызов вашей функции инициализации(). Используйте следующее:

function init():void 
{ 
     blogButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
     homeButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
     portfolioButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
     aboutButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
     signButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 
     contactButton.addEventListener(MouseEvent.CLICK,onActionPerformed); 

}// end function 

function onActionPerformed(e:MouseEvent):void 
{ 
switch(e.currentTarget) 
{ 
    case homeButton: navigateToURL(new URLRequest("http://google.com"), "_blank"); break; 
    case blogButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
    case portfolioButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
    case aboutButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
    case signButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 
    case contactButton: navigateToURL(new URLRequest("http://google.com"), "_self"); break; 

}// end switch 

}// end function 

init(); 
1

Вы не используете функцию init, чтобы слушатели не были установлены.

init(); 
Смежные вопросы