Previous Page
Next Page

Tripod >> 3pod Tips & Learning and manuals for educations

Recipe 8.9. Creating Multiline Text

Problem

You want to display multiple lines of text and/or allow the user to input multiple lines of text.

Solution

Use a text area component.

Alternatively, use a dynamic or input text field and select Multiline or Multiline No Wrap from the Line type menu in the Property inspector. Optionally, you can set the text field's multiline property to TRue via ActionScript.

Discussion

There are two ways you can work with multiple lines of text within Flash: a text area component and a text field instance that has been configured to accept multiple lines. Each option has its own advantages and disadvantages.

The text area component provides functionality much like the text area form control in HTML. The text input component allows a single line of input; the text area component allows multiple lines of input. However, the text area component is not only for input, but also for displaying text. It provides automatic scrolling functionality, so that if the text extends beyond the boundaries of the text area, a scrollbar will appear, allowing the user to scroll to see the entire contents. That makes text area components useful both for allowing a user to input multiple lines of content and for displaying text content.

To use the text area, complete the following steps:

  1. Drag an instance from the Components panel onto the stage.

  2. Give the instance a name (exp 3pod.com) in the Property inspector.

  3. If you want to assign a text value to the component instance, you can do so either at authoring time or runtime:

  • You can assign a text value at authoring time by way of the Component Inspector panel. Assign the value to the text parameter.

  • You can assign a text value at runtime using the text property of the instance. For example, the following code assigns a value to a text area with an instance name (exp 3pod.com) of ctaOutput:

    	ctaOutput.text = "Flash Cookbook";
    

    Assigning values to text area components at runtime instead of authoring time has plenty of potential advantages. One of the most significant is that you can load data from an external file and use it to populate the text area. For more information on loading text from external files, see Chapter 19.

The text area component has several advantages. One is that it is very simple to set up scrollable text with a text areasomething that is a little more complicated with a standard text field. Additionally, because the text area component is built on the same framework as the other Macromedia UI components, you can use built-in features such as style management to quickly change the styles of all components in your Flash application. However, the text area is not without disadvantages. As with many of the Macromedia UI components, the text area can add a hefty increase to your .swf file's size. A .swf file with nothing other than a text area is already 40KB. Furthermore, if you want to customize the scrollbars beyond simple style changes(changing the color, and so on), you're likely to find it more of a hassle than it's worth.

The other option for accepting and displaying multiple lines of text is to use a dynamic or input text field. By default, dynamic and input text fields display only a single line. A single-line text field won't display more than one line of text, even if you include line breaks in the text value or if the user presses the Enter key while entering text. In order for a text field to accommodate multiple lines of text, you must tell Flash that it is a multiline text field. You can do this either at authoring time or at runtime.

At authoring time, you can make a text field multiline by selecting it with the Selection tool and then selecting the Multiline or Multiline No Wrap option from the Line type menu in the Property inspector. The Multiline option creates a multiline text field that automatically performs word wrapping. The Multiline No Wrap option creates a multiline text field that does not perform automatic word wrapping.

You can also tell Flash to make a text field multiline at runtime using ActionScript. The multiline property can be either true or false. It defaults to false, but setting it to true allows the text field to accommodate multiple lines:

	tField.multiline = true;

See Recipe 8.11 for more information about controlling word wrapping of multiline text fields at runtime.

Tripod >> 3pod Botom Tips & Learning and manuals for educations

Previous Page
Next Page

 

bluedot bluedots greydots pinkdots

Tripod >> 3pod Tips & Learning and manuals for educations