views:

1023

answers:

1

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?

+3  A: 

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

nerdabilly