I create a TextArea in actionscript:
var textArea:TextArea = new TextArea();
I want it to have a black background. I've tried
textArea.setStyle("backgroundColor", 0x000000);
and I've tried
textArea.opaqueBackground = 0x000000;
but the TextArea stays white. What should I do?
TextArea is a UI component built from TextField and other Flash built-in classes and UIComponents. As with most of the Adobe UI components, nothing is as it seems when setting properties. To set the color of the area behind the text in the TextArea, you need to actually set the opaque background of its internal TextField using the textField property:
var textArea:TextArea = new TextArea()
textArea.textField.opaqueBackground = 0x000000;
Of course now that the background is black, the text can't also be black, so we change its color using a new TextFormat:
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xffffff;
textArea.setStyle("textFormat",myFormat);
then just set the text and add to stage:
textArea.text = "hello";
addChild(textArea);
Also, if you want a little more control, there's a nice extension class here that fixes a lot of the problems with TextArea:
http://blog.bodurov.com/Post.aspx?postID=14
Here is what worked for me, which I discovered on my own after reviewing updated AC3 documentation
TextArea - Background Color, 2011 AC3
Took me forever to realize that in AC3, as of now (2011), they officially tell you to use spark TextArea instead of mx
(s:TextArea
instead of mx:TextArea
)
<s:TextArea
id="joy_text"
color="0xFF0000"
contentBackgroundColor="0x000000"
text = "joy"
/>
Please Note
color = font color
make sure to include in your namespaces: (up at top of .mxml file)
xmlns:s="library://ns.adobe.com/flex/spark"