在滚动时更改Alpha;不改变鼠标输出?

时间:2013-05-07 07:06:12

标签: actionscript-3 flash

所以我有一个Tile类,带有一个sprite变量,用于保存tile的图形。鼠标悬停时,我ColorTransform图形。似乎工作正常。鼠标移出后,我尝试将其更改回来。纳达。事实上,两次滚动相同的瓷砖会增加alpha,直到它最终完全消失。不知道如何解决它。这是我的代码。

在Tile类中:

this.addEventListener(MouseEvent.MOUSE_OVER, thisMouseOver);
this.addEventListener(MouseEvent.MOUSE_OUT, thisMouseOut );

public function thisMouseOver( e:Event ):void {
    tileGraphic.bitmapData = setAlpha(tileGraphic.bitmapData);
}

public function thisMouseOut( e:Event ):void {
    tileGraphic.bitmapData = resetAlpha(tileGraphic.bitmapData);
}

private function setAlpha( bmd:BitmapData ):BitmapData {
    var rec:Rectangle = new Rectangle( 0, 0, bmd.width, bmd.height );
    var ct:ColorTransform = new ColorTransform();
    ct.alphaMultiplier = .65;
    bmd.colorTransform( rec, ct );
    return bmd;
} //end function setAlpha

private function resetAlpha( bmd:BitmapData ):BitmapData {
    var rec:Rectangle = new Rectangle( 0, 0, bmd.width, bmd.height );
    var ct:ColorTransform = new ColorTransform();
    ct.alphaMultiplier = 1;
    bmd.colorTransform( rec, ct );
    return bmd;
} //end function resetAlpha

有人能指出我正确的方向吗?谢谢!

2 个答案:

答案 0 :(得分:1)

替换resetAlpha
    private function resetAlpha( bmd:BitmapData ):BitmapData {
        var rec:Rectangle = new Rectangle( 0, 0, bmd.width, bmd.height );
        var ct:ColorTransform = new ColorTransform();
        ct.alphaOffset = 255
        bmd.colorTransform( rec, ct );
        return bmd;
    } //end function resetAlpha

答案 1 :(得分:1)

您应该更好地更改容器的alpha而不是使用BitmapData像素。例如,在您的情况下,如果您的图块位图最初将具有透明像素(在绘制事物之前将其填充为0x00ff0000并检查是否如此),它们将变得不透明,并且编码为buddha。因此,将侦听器更改为以下内容:

public function thisMouseOver( e:Event ):void {
    tileGraphic.alpha=0.65;
}

public function thisMouseOut( e:Event ):void {
    tileGraphic.alpha=1;
}