2010-12-11 14 views
0

6つのボタンが同じレイヤーにあり、すべてがホバーオーバーエフェクトとソートされています。ただどこにも行かない、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; 
    } 
} 

エラーなし、またはエラーをコンパイル:しかし私は、次のコードが動作していないされていない、それぞれのインスタンス名を割り当てられ、そしてGoogleに各画像をリンクするActionScriptを作ってみました。 http://danlamanna.com/misc/navigation.fla

+0

場合onActionPerformed()メソッドの最初の行にtrace(e.currentTarget)を置くと、期待どおりの出力が得られますか? – greggreg

+0

いいえ、以前はFlashで出力していませんでしたので、googleがムービーウィンドウでポップアップするか、デフォルトのブラウザを開くと思いますか?いずれにしてもそれはどちらもしません。 –

+0

ボタンをクリックしたときに出力が生成されない場合、問題はメソッド呼び出しの前です。トレースステートメントを試しましたか?フラッシュで出力パネルに出力します。あなたのアプリケーションの始めにコーディングを試してみてください: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

あなたはあなたののinit()関数の呼び出しを追加する必要があります。

EDITコードは、しかし、まだ私はほとんどの現在のFLAファイルをダウンロードするためのリンクを行って機能していない、わずかに修正されました。以下を使用してください:

1

リスナーが設定されていないように、関数initを実行していません。

init(); 
関連する問題