如何更改 actionscript 中 textarea 的颜色?

Sim*_*mon 2 flash actionscript skinning

我在 actionscript 中创建了一个 TextArea:

var textArea:TextArea = new TextArea();
Run Code Online (Sandbox Code Playgroud)

我希望它有黑色背景。我试过了

textArea.setStyle("backgroundColor", 0x000000);
Run Code Online (Sandbox Code Playgroud)

我试过了

textArea.opaqueBackground = 0x000000;
Run Code Online (Sandbox Code Playgroud)

但 TextArea 保持白色。我该怎么办?

ner*_*lly 5

TextArea 是由 TextField 和其他 Flash 内置类和 UIComponents 构建的 UI 组件。与大多数 Adob​​e UI 组件一样,在设置属性时似乎没有什么。要在 TextArea 中设置文本后面区域的颜色,您需要使用 textField 属性实际设置其内部 TextField 的不透明背景:

var textArea:TextArea = new TextArea()
textArea.textField.opaqueBackground = 0x000000;
Run Code Online (Sandbox Code Playgroud)

当然现在背景是黑色的,文本也不能是黑色的,所以我们使用一个新的 TextFormat 来改变它的颜色:

var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xffffff;
textArea.setStyle("textFormat",myFormat);
Run Code Online (Sandbox Code Playgroud)

然后只需设置文本并添加到舞台:

textArea.text = "hello";
addChild(textArea); 
Run Code Online (Sandbox Code Playgroud)

另外,如果你想要更多的控制,这里有一个很好的扩展类,它修复了 TextArea 的很多问题:

http://blog.bodurov.com/Post.aspx?postID=14