Justin
Justin

Reputation: 11

Why is TextFormat not working on my TextArea?

I am trying to generate bold text on a text area once its clicked. What am I doing wrong?

HelloWorld.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="800" height="800">
    <mx:Script source="HelloWorldAS.as" />

        <mx:VBox width="70%" height="70%" label="Container">
            <mx:TextArea id="lblTest"  verticalScrollPolicy="off" focusThickness="0" borderThickness="0" borderStyle="none" editable="true" fontFamily="Arial" fontSize="14" width="100%" height="100%" click="areaClick()"/>
        </mx:VBox>

</mx:Application>

HelloWorldAS.as

// ActionScript file
import flash.text.TextField;
import flash.text.TextFormat;

public function areaClick() : void{
    lblTest.text = "Hello world!";

    var format:TextFormat = new TextFormat();
    format.bold=true;

    lblTest.setStyle("textFormat", format);
    lblTest.validateNow();
}

Upvotes: 0

Views: 281

Answers (2)

gbdcool
gbdcool

Reputation: 982

Unfortunately there is no textFormat style for TextArea. Use fontWeight as bold as below:

lblTest.setStyle("fontWeight", "bold");

Upvotes: 1

Nbooo
Nbooo

Reputation: 865

You can read the official adobe documentation here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextFormat.html, the most interesting part for you is:

Use the TextField.defaultTextFormat property to apply formatting BEFORE you add text to the TextField, and the setTextFormat() method to add formatting AFTER you add text to the TextField.

So if you want the text "hello world" to be bold, you must apply the TextFormat as follows:

lblText.setTextFormat(format);

Upvotes: 0

Related Questions