如何更改ActionScript中的textarea的颜色

如何更改ActionScript中的textarea的颜色

本文介绍了如何更改ActionScript中的textarea的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ActionScript中创建一个文本区:

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);

和我试过

textArea.opaqueBackground = 0x000000;

但文本区停留白色。我该怎么办?

but the TextArea stays white. What should I do?

推荐答案

文本区为TextField和其它Flash内置类和UIComponents的内置UI组件。与大多数的Adobe UI组件的,没有什么,因为它似乎设置属性时。要设置在文本区文本后面的区域的颜色,则需要使用textField属性实际上设置它的内部文本字段的不透明的背景:

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;

当然,现在的背景是黑色,文字不能同时是黑色的,所以我们采用了新的TextFormat改变它的颜色:

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

这篇关于如何更改ActionScript中的textarea的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:33