Reputation: 23
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
Reputation: 18193
Note there are 3 TextInput
classes.
fl.controls.TextInput -- this is from Flash Professional, and it's not very useful in Flex apps. It's the one that has a "textFormat" style (the Flex one's do not have such a style).
mx.controls.TextInput -- an older Flex component from the Flex 3 SDK
spark.components.TextInput -- the Spark version of the component in the Flex 4 SDK
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