Using ActionScript 3.0 Components |
|
|
|
| Using the UI Components > Using the TextArea > Creating an application with the TextArea | |||
The following procedure explains how to add a TextArea component to an application while authoring. The example sets up a focusOut event handler on the TextArea instance that verifies that the user typed something in the text area before giving focus to a different part of the interface.
To create an application with the TextArea component:import flash.events.FocusEvent;aTa.restrict = "a-z,'\" \"";aTa.addEventListener(Event.CHANGE,changeHandler);aTa.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, k_m_fHandler);aTa.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, k_m_fHandler);function changeHandler(ch_evt:Event):void {bTa.text = aTa.text;}function k_m_fHandler(kmf_event:FocusEvent):void {kmf_event.preventDefault();}
This example restricts the characters you can enter into the aTa text area to lowercase characters, the comma, the apostrophe, and spaces. It also sets up event handlers for the change, KEY_FOCUS_CHANGE, and MOUSE_FOCUS_CHANGE events on the aTa text area. The changeHandler() function causes the text that you enter in the aTa text area to automatically appear in the bTa text area by assigning aTa.text to bTa.text on each change event. The k_m_fHandler() function for the KEY_FOCUS_CHANGE and MOUSE_FOCUS_CHANGE events prevents you from pressing the Tab key to move to the next field without entering any text. It does this by preventing the default behavior.
If you press the Tab key to move focus to the second text area without entering any text, you should see an error message and focus should return to the first text area. As you enter text in the first text area, you will see it duplicated in the second text area.
The following example creates a TextArea component with ActionScript. It sets the condenseWhite property to true to condense white space and assigns text to the htmlText property to take advantage of HTML text formatting attributes.
To create a TextArea instance using ActionScript:import fl.controls.TextArea;var aTa:TextArea = new TextArea();aTa.move(100,100);aTa.setSize(200, 200);aTa.condenseWhite = true;aTa.htmlText = ' <b>Lorem ipsum dolor</b> sit amet, consectetuer adipiscing elit. <u>Vivamus quis nisl vel tortor nonummy vulputate.</u> Quisque sit amet eros sed purus euismod tempor. Morbi tempor. <font color="#FF0000">Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos.</font> Curabitur diam. Suspendisse at purus in ipsum volutpat viverra. Nulla pellentesque libero id libero.';addChild(aTa);
This example uses the htmlText property to apply HTML bold and underline attributes to a block of text and display it in the a_ta text area. The example also sets the condenseWhite property to true to condense the white space within the text block. The setSize() method sets the text area's height and width, and the move() method sets its position. The addChild() method adds the TextArea instance to the Stage.
|
|
|
|