开发者

Flex: Hide (or Remove) Label Text without Changing the Button Size

I have a button with variable-length of label text. I have a User Setting that can turn on or off the label text on this button.

How can I implement this?

NOTE: the button's background has a gradient color.

I tried using BlendMode.LAYER, no luck;

I tried using Button.resizeHandler

    private function resizeHandler(event:ResizeEvent):void
    {
        if (event.oldWidth > this.width)
            this.width = event.oldWidth;
        if (event.oldHeight > this.heigh开发者_Go百科t)
            this.height = event.oldHeight;
    }

but it only worked if the initial UserSetting value is true.

How about embedded font? I don't know how to apply it to button


You can use the property minWidth and maxWidth. minWidth to specify the minimum width that the button should have. and maxWidth to specify the maximum width the button can have.


You can extend mx.controls.Button to add a show/hide label function. The text field is a protected property so you can just set the visibility on/off in your function. Leave Flex to measure everything correctly itself.

If you want to grow/shrink the button when the text is on or off, you can also set the button width. You will have to calculate the width based on the textfield width.


What happens if you just set the button's width? That way, it should be a constant width no matter what you set as the label.

Most likely width is being calculated in the updateDisplayList method. So, code in your resize handler may be being reset at the next render event.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜