1

スプライトをTextAreaの親として、マウスオーバーで0.5アルファで表示される背景を取得して成功していません。私が得ることができる最高のものは、MouseOverで0.5の透明度で表示されるテキストです。これは、私が探しているものではありません。マウスの状態に関係なく最大アルファでテキストを表示し、MouseOverでは背景(スプライト)のみを半分の透明度で表示したいと思います。できればトゥイーンは避けたいです。これが私のコードです:

var textSprite:Sprite  = new Sprite();

    public function Main()
    {
        textSprite.graphics.beginFill(0x000000, 0);
        textSprite.graphics.drawRect(94.95, 80.95, 390, 130); 
        textSprite.graphics.endFill();
        textSprite.addChild(picArea1);//textarea added on stage, same dimensions, transparent background
        textSprite.buttonMode = true;
        textSprite.useHandCursor = true;
        stage.addChild(textSprite);


        textSprite.addEventListener(MouseEvent.MOUSE_OVER, applyAlpha);
        textSprite.addEventListener(MouseEvent.MOUSE_OUT, noApplyAlpha);
    }

    function applyAlpha(event:MouseEvent):void {
       textSprite.alpha = 0.5;
    }

    function noApplyAlpha(event:MouseEvent):void {
       textSprite.alpha = 0;
    }
4

1 に答える 1

0

スプライトのアルファを設定すると、現在の問題であるすべての子(設計上)にも影響します。

現在行っている方法(グラフィックスオブジェクトを使用して背景を描画する)では、マウスオーバー/アウトでスプライトのグラフィックスを再描画する必要があります。

使用できる方法は次のとおりです。

public function Main()
{
    drawTextBG(); //a new function I made to avoid duplicating code
    textSprite.addChild(picArea1);//textarea added on stage, same dimensions, transparent background
    textSprite.buttonMode = true;
    textSprite.useHandCursor = true;
    stage.addChild(textSprite);


    textSprite.addEventListener(MouseEvent.MOUSE_OVER, applyAlpha);
    textSprite.addEventListener(MouseEvent.MOUSE_OUT, noApplyAlpha);
}

//new function I made, this draws the background and makes the transparency the value passed in. I set the default to 1 (totally visible)
function drawTextBG(bgAlpha:Number = 1):void {
    textSprite.graphics.clear();
    textSprite.graphics.beginFill(0x000000, bgAlpha);
    textSprite.graphics.drawRect(94.95, 80.95, 390, 130); 
    textSprite.graphics.endFill();
}

function applyAlpha(event:MouseEvent):void {
   drawTextBG(.5); //redraw the background with half (.5) alpha
}

function noApplyAlpha(event:MouseEvent):void {
   drawTextBG(); //redraw the background with the default value (1 - totaly visible)
}

これで、TLF(text-layout-framework)テキストフィールドを使用している場合は、テキストフィールドのbackgroundColorプロパティとbackgroundAlphaプロパティを使用するだけで、手動で背景を描画する必要がなくなります。

于 2012-09-14T21:13:10.653 に答える