Monday, July 19, 2010

Use appendText

In AS3, the TextField class has a new method called appendText. In this Actionscript 3 tutorial we will see why and how should we use it.

Say, you need to add some text to an already existing textfield... A simple way of doing that is to use the += operator, like this:

var tfield = new TextField();
tfield.text = "Greetings"
tfield.text += " from Kirill"
// "Greetings from Kirill"

The new appendText method does the same, but it is a more efficient and faster way of doing it.

var tfield = new TextField();
tfield.text = "Greetings"
tfield.appendText(" from Kirill");
// "Greetings from Kirill"

No comments:

Post a Comment