Flex - 在TextArea中切换粗体文本

时间:2011-10-11 20:54:46

标签: flex text bold

我在Flex中制作RTE并尝试制作文本格式按钮。

<s:ToggleButton id="boldBtn" width="50" height="50" label="B" click="boldBtn_clickHandler(event)" color="#000000" fontWeight="bold"/>

和我的代码

protected function boldBtn_clickHandler(event:MouseEvent):void
        {
            var txtLayFmt:TextLayoutFormat = mainTextField.getFormatOfRange(null,
                mainTextField.selectionAnchorPosition,
                mainTextField.selectionActivePosition);
            txtLayFmt.fontWeight = (txtLayFmt.fontWeight == FontWeight.BOLD) ? FontWeight.NORMAL : FontWeight.BOLD; **// Causing the NULL Pointer exception**
            mainTextField.setFormatOfRange(txtLayFmt,
                mainTextField.selectionAnchorPosition,
                mainTextField.selectionActivePosition);
            mainTextField.setFocus();
        }

当我在TextArea中键入一些文本并选择它时,然后单击boldBtn我得到一个无法访问属性或空对象引用的方法。如果我注释掉txtLayFmt.fontWeight =(txtLayFmt.fontWeight == FontWeight.BOLD)? FontWeight.NORMAL:FontWeight.BOLD;该程序没有崩溃所以这似乎是违规行,但我不明白为什么。

修改 我现在正在尝试这段代码。当我在桌面应用程序中使用它时,它可以工作,但是当我将它放在移动项目中时,它不起作用。有什么想法吗?

......

private function btnBold_click(evt:MouseEvent):void {
trace("Clicked"); // Traces to output ok
var styleObj:TextLayoutFormat = new TextLayoutFormat();
styleObj.fontWeight = FontWeight.BOLD;
mainTextField.setFormatOfRange(styleObj);
}

这段代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

将此添加到您的css,它将使用TLF并支持所有正常功能。

form.username(placeholder="username")
相关问题