Nick M
Nick M

Reputation: 23

Flex 4.6: setting a textFormat on textInput

I'm trying to set a textFormat on a textInput component. Like so:

var testText:TextInput = new TextInput();
testText.text = "TESTING";
addChild(testText);

var tf:TextFormat = new TextFormat();
tf.leftMargin = 50;
tf.size = 20;
tf.color = 0xFF0000;
testText.setStyle("textFormat", tf);

According to the adobe documentation (and numerous examples on the web) this should be possible. Yet the text never has its style applied. I've tried with both a spark and an MX TextInput (and even a TextArea) yet the results are always the same. Am I missing something? Or is this no longer a supported operation?

Upvotes: 0

Views: 2330

Answers (1)

Sunil D.
Sunil D.

Reputation: 18193

Note there are 3 TextInput classes.

The last two don't have a "textFormat" style, so your code above won't work.

Rather than trying to use that "textFormat" style, you can use individual styles that the Flex components support ... these are somewhat tedious to apply in Actionscript, but easy in MXML. The docs that I linked to have a styles section, where you can see what styles are available to apply to the text...

AS3:

var t:TextInput = new TextInput();
t.setStyle("fontSize", 18);
t.setStyle("color", 0xFF0000);

MXML:

<s:TextInput fontSize="18" color="0xFF0000" />

Upvotes: 2

Related Questions