Muhammad Umar
Muhammad Umar

Reputation: 11782

How can I save the previous text in textarea

I am using a button to input text from a text input and displaying it in a text area using following code.

public function sendMessage():void
{
    mytextarea.text = textinput.text;
    textinput.text = "";
}

The problem I am facing is , whenever I add new line or others it replaces the previous text, I want the previous text in text area to stay there.

Any hints how to do that?

Upvotes: 0

Views: 139

Answers (2)

Marty
Marty

Reputation: 39456

Building on @taskinoor 's answer, you should try use appendText() where possible over the += operator.

From documentation for flash.text.TextField:

Appends the string specified by the newText parameter to the end of the text of the text field. This method is more efficient than an addition assignment (+=) on a text property (such as someTextField.text += moreText), particularly for a text field that contains a significant amount of content.

Parameters

newText:String — The string to append to the existing text.

So your code would be:

mytextarea.appendText(textinput.text);

Upvotes: 1

taskinoor
taskinoor

Reputation: 46027

Instead of setting the text, append new text with the previous texts.

mytextarea.text += textinput.text;

Upvotes: 4

Related Questions