开发者

Flash "visible" issue

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
开发者_Python百科    {           
        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".


Wait a frame between setting visible and calling changed(). Use the invalidateProperties()/commitProperties() model.

private bool _isChanged = false;
private function onVisibleChange():void
{
            _layer.visible = layerVisible.selected;
            _isChanged = true;
            invalidateProperties();
}

protected override function commitProperties():void {
    super.commitProperties();

    if (_isChanged) {
        _isChanged = false;
        changed();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜