Flex - переключать полужирный текст в TextArea - PullRequest
1 голос
/ 12 октября 2011

Я делаю RTE во Flex и пытаюсь сделать кнопки форматирования текста.

<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 голосов
/ 12 августа 2015

добавьте это к вашему CSS, и он будет использовать TLF и поддерживать все нормальные функции.

s|TextArea
{
    skinClass: ClassReference("spark.skins.spark.TextAreaSkin");
}
...