1

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 をクリックすると、null オブジェクト参照のプロパティまたはメソッドにアクセスできません。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);
}

このコードの何が問題になっていますか?

4

1 に答える 1

0

これを CSS に追加すると、TLF が使用され、通常の機能がすべてサポートされます。

s|TextArea
{
    skinClass: ClassReference("spark.skins.spark.TextAreaSkin");
}
于 2015-08-12T01:20:40.540 に答える