2012-04-11 7 views
1

どうすればこの作品を作成できますか?実際の色合いを参照するために、参照から単語Buttonを削除する必要があります。前もって感謝します。AS3リファレンスボタン

disagreeButton.addEventListener(MouseEvent.ROLL_OVER, mouseRollOver); 
contentMain.clickButton1.addEventListener(MouseEvent.ROLL_OVER, mouseRollOver); 

function mouseRollOver(e:MouseEvent):void { 
    var c:Color = new Color(); 
    c.setTint (0xFFFFFF, 1); 
    //the issue is this line: 
    this[e.target.name.replace("Button", "")].transform.colorTransform = c; 
} 
+1

は、このソリューションの何が問題になっているのですか?それはコンパイルされますか?走る?予期しない副作用がありますか? –

+0

TypeError:エラー#1010:用語は定義されておらず、プロパティもありません。 index_test_flaで \t :: MainTimeline/mouseRollOver() は唯一の "contentMain.clickButton1" のために、このエラーが出る – Anderson

+0

あなたはe.target.name.replace( "ボタン" は、 "") 'あなたはどう思うかと評価する'ことをテストしていますします? –

答えて

1

私はあなたの問題を理解したので、以下のことをお勧めします。

  1. thisのボタン用に別の方法を持っている、とcontentMainで、かつ他のもの。適切な場合は、this[...]またはcontentMain[...]でオブジェクトにアクセスします。

    disagreeButton.addEventListener(MouseEvent.ROLL_OVER, mainMouseRollOver); 
    contentMain.clickButton1.addEventListener(MouseEvent.ROLL_OVER, contentMainMouseRollOver); 
    
    function mainMouseRollOver(e:MouseEvent):void { 
        mouseRolloverLogic(this[e.target.name.replace("Button", "")]; 
    } 
    
    function contentMainMouseRollOver(e:MouseEvent):void { 
        mouseRolloverLogic(contentMain[e.target.name.replace("Button", "")]; 
    } 
    
    function mouseRolloverLogic(item:DisplayObject):void { 
        var c:Color = new Color(); 
        c.setTint (0xFFFFFF, 1); 
        item.transform.colorTransform = c; 
    } 
    
  2. 余分なロジックをメソッドに追加します。

    if (this[...] != null) { 
        ... 
    }else if (contentMain[...] != null) { 
        ... 
    } 
    
+0

ありがとうございます。これを行うかどうかを「きれいに」する方法はありますか? – Anderson

+0

@Anderson最初のオプションはおそらく「クリーナー」と考えられます。メインアプリケーションの 'contentMain'とButtonsのボタンに対して異なる' mouseRollOver'関数を作成するだけです。 –

+0

目標の違いのためだけに機能を繰り返すように変わっているようです。私はちょうど主要なタイムライン上のすべてのコードを持つより効率的な方法があると思った。 – Anderson