【问题标题】:How do I change the colours of a textarea in actionscript?如何更改动作脚本中文本区域的颜色?
【发布时间】:2010-09-15 13:20:36
【问题描述】:

我在 actionscript 中创建了一个 TextArea:

var textArea:TextArea = new TextArea();

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

textArea.setStyle("backgroundColor", 0x000000);

我试过了

textArea.opaqueBackground = 0x000000;

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

【问题讨论】:

    标签: flash actionscript skinning


    【解决方案1】:

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

    var textArea:TextArea = new TextArea()
    textArea.textField.opaqueBackground = 0x000000;
    

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

    var myFormat:TextFormat = new TextFormat();
    myFormat.color = 0xffffff;
    textArea.setStyle("textFormat",myFormat);
    

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

    textArea.text = "hello";
    addChild(textArea); 
    

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

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

    【讨论】:

      【解决方案2】:

      这是我在查看更新的 AC3 文档后自己发现的方法

      TextArea - 背景颜色,2011 AC3

      让我永远意识到,在 AC3 中,截至目前(2011 年),他们正式告诉你使用 spark TextArea 而不是 mx

      s:TextArea 而不是mx:TextArea

      <s:TextArea
      id="joy_text"
      color="0xFF0000"
      contentBackgroundColor="0x000000"
      text = "joy"
      />
      

      请注意

      颜色 = 字体颜色

      确保包含在您的命名空间中:(在 .mxml 文件的顶部)

      xmlns:s="library://ns.adobe.com/flex/spark"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-03
        • 2021-03-29
        • 1970-01-01
        • 2012-06-16
        • 1970-01-01
        相关资源
        最近更新 更多