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 assomeTextField.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);
精彩评论