0
votes

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?

1
yeah those were the old days. But now, with skins, CSS, and TLF there is truly very little limit to the high speed styling you can do. Easiest for you would be just define a CSS style and use styleName="myStyle".Jason Reeves

1 Answers

2
votes

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" />