在flex 3中,需要将复选框标签的一部分设为粗体

时间:2012-09-03 15:21:39

标签: actionscript-3 flex flex3

在flex 3中,如何使复选框标签的一部分以粗体显示? 说复选框标签是“记住datagrid上的值”。需要使文本“datagrid”单独加粗。任何人都可以请帮助。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

这不是一个完美的解决方案,但它会让你开始。如果扩展CheckBox类,则可以覆盖updateDisplayList()方法,并使用htmlText属性设置复选框的标签。

然后使用此自定义复选框并使用HTML传递标签。

此解决方案的问题:

  • 超类不测量HTML格式的文本(您可以实现measure() Flex生命周期方法)
  • 在super.updateDisplayList()完成所有工作之后,我们将使用htmlText属性
  • 对其进行撤消

HTMLTextCheckBox.as:

package
{
    import mx.controls.CheckBox;

    public class HtmlTextCheckBox extends CheckBox
    {
        public function HtmlTextCheckBox()
        {
            super();
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            textField.htmlText = label;
        }
    }
}

使用它MXML:

<local:HtmlTextCheckBox label="this is the &lt;b&gt;bold part&lt;/b&gt;"/>

或者在AS3中:

var cb:HtmlTextCheckBox = new HtmlTextCheckBox();
cb.text = "this is the <b>bold part</b>";