Flash "visible" issue

Posted by justkevin on Stack Overflow See other posts from Stack Overflow or by justkevin
Published on 2010-04-21T23:07:22Z Indexed on 2010/04/21 23:43 UTC
Read the original article Hit count: 367

Filed under:
|
|

I'm writing a tool in Flex that lets me design composite sprites using layered bitmaps and then "bake" them into a low overhead single bitmapData. I've discovered a strange behavior I can't explain: toggling the "visible" property of my layers works twice for each layer (i.e., I can turn it off, then on again) and then never again for that layer-- the layer stays visible from that point on.

If I override "set visible" on the layer as such:

override public function set visible(value:Boolean):void
    {           
        if(value == false) this.alpha = 0;
        else {this.alpha = 1;}
    }

The problem goes away and I can toggle "visibility" as much as I want. Any ideas what might be causing this?

Edit:

Here is the code that makes the call:

private function onVisibleChange():void
{
            _layer.visible = layerVisible.selected;
            changed();
}

The changed() method "bakes" the bitmap:

public function getBaked():BitmapData
    {
        var w:int = _composite.width + (_atmosphereOuterBlur * 2);
        var h:int = _composite.height + (_atmosphereOuterBlur * 2);
        var bmpData:BitmapData = new BitmapData(w,h,true,0x00000000);
        var matrix:Matrix = new Matrix();
        var bounds:Rectangle = this.getBounds(this);
        matrix.translate(w/2,h/2);
        bmpData.draw(this,matrix,null,null,new Rectangle(0,0,w,h),true);
        return bmpData;
    }

Incidentally, while the layer is still visible, using the Flex debugger I can verify that the layer's visible value is "false".

© Stack Overflow or respective owner

Related posts about flash

Related posts about flex