开发者

How can I save the previous text in textarea

开发者 https://www.devze.com 2023-04-10 12:01 出处:网络
I am using a button to input text from a text input and displaying it in a text area using following code.

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;
    开发者_Go百科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?


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

mytextarea.text += textinput.text;


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消