Adobe Flex 3 Help

About text controls

You use Flex text-based controls to display text and to let users enter text into your application. The following table lists the controls, and indicates whether the control can have multiple lines of input instead of a single line of text, and whether the control can accept user input:

Control

Multiline

Allows user Input

Label

No

No

TextInput

No

Yes

Text

Yes

No

TextArea

Yes

Yes

RichTextEditor

Yes

Yes

All controls except the RichTextEditor control are single components with a simple text region; for example, the following image shows a TextInput control in a simple form:

TextInput control in a simple form

The following code produces the preceding image:

<?xml version="1.0"?>
<!-- textcontrols/FormItemLabel.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
  <mx:Form id="myForm" width="500" backgroundColor="#909090">
     <!-- Use a FormItem to label the field. -->
     <mx:FormItem label="First Name">
        <mx:TextInput id="ti1" width="150"/>
     </mx:FormItem>
  </mx:Form>
</mx:Application>

The executing SWF file for the previous example is shown below:

The RichTextEditor control is a compound control; it consists of a Panel control that contains a TextArea control and a ControlBar with several controls for specifying the text format and HTTP links. The following image shows a RichTextEditor control:

The RichTextEditor control is a compound control; it consists of a Panel control that contains a TextArea control and a ControlBar control

The following code produces the preceding image:

<?xml version="1.0"?>
<!-- textcontrols/RTECDATA.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
  <mx:RichTextEditor id="rte1" title="Rich Text Editor">
     <mx:htmlText>
        <![CDATA[
           <p align='center'><b><font size='16'>HTML Text</font></b>
           </p>This paragraph has <font color='#006666'><b>bold teal text.
           </b></font>
        ]]>
     </mx:htmlText>
  </mx:RichTextEditor>
</mx:Application>

The executing SWF file for the previous example is shown below:

Flex text-based controls let you set and get text by using the following properties:

text  

Plain text without formatting information. For information on using the text property, see Using the text property.



htmlText  

Rich text that represents formatting by using a subset of HTML tags, and can include bulleted text and URL links. For information on using the htmlText property, see Using the htmlText property.



Both properties set the same underlying text, but you can use different formats. For example, you can do the following to set, modify, and get text:

  • You can set formatted text by using the htmlText property, and get it back as a plain text string by using the text property.
  • You can set formatted text in user-editable text controls (TextInput, TextArea, RichTextEditor) by setting the text string with the text property and formatting a section of this text by using the TextRange class. If you get the text back by using the htmlText property, the property string includes HTML tags for the formatting. For more information on using the TextRange class, see Selecting and modifying text.