ozr3n
ozr3n

Reputation: 81

AS3 : if textfield.text is a string, why string functions does not work on it?

I have a declaration:

private var textField:TextField = new TextField(220, 35, "Tap to flip the text!", "Roboto", 22, 0xf1f1f1, false);

and then I have command:

textField.text.split("").reverse().join("");

which I found here: http://curtismorley.com/2007/10/18/as3-quicktip-reversing-a-string-with-one-line-of-code/

Can someone explain to me why this command doesn't reverse this string?

Upvotes: 1

Views: 194

Answers (2)

Fygo
Fygo

Reputation: 4675

private var textField:TextField = new TextField(220, 35, "Tap to flip the text!", "Roboto", 22, 0xf1f1f1, false);

Where did you take that declaration from? It should have thrown you an error immediately.

TextField () Constructor public function TextField()

Language Version: ActionScript 3.0 Runtime Versions: AIR 1.0, Flash Player 9, Flash Lite 4

Creates a new TextField instance. After you create the TextField instance, call the addChild() or addChildAt() method of the parent DisplayObjectContainer object to add the TextField instance to the display list.

The default size for a text field is 100 x 100 pixels.

Once you fix that, it will work just fine.

Upvotes: 0

BadFeelingAboutThis
BadFeelingAboutThis

Reputation: 14406

It does reverse the string. You don't see it though because you're not assigning the new value back to the textField.

textField.text = textField.text.split("").reverse().join("");

anything except an = after the text property will just be reading the value, not assigning it.

Also, your code isn't a valid textField, are you using some other extension of it?

Upvotes: 1

Related Questions