【问题标题】:AS3 Rounded Text FieldAS3 圆形文本字段
【发布时间】:2010-11-16 10:53:18
【问题描述】:

有人知道如何在 AS3 中创建具有可见边框和圆角的动态文本字段吗?

我想我可能需要创建一个圆形动画剪辑,调整大小并将其放在文本后面。

我试过了,但我没有看到任何变化。

var styleRound:StyleSheet = new StyleSheet();
styleRound.parseCSS("h4{cornerRadius:10;borderStyle: solid; borderThickness: 1;}");
tf.htmlText = "<h4>" + hotspotData.caption + "</h4>";
tf.styleSheet = styleRound;

【问题讨论】:

  • 使用标签 actionscript-3。您将获得更多观看次数。 :D

标签: actionscript-3 dynamic textfield rounded-corners


【解决方案1】:

这是available CSS styles for TextFields in ActionScript 3 的列表。抱歉,没有圆角半径。

您可以为 TextField 对象 border property 上的文本字段打开边框。但是拐角处没有可用的属性。

我建议您创建一个新组件并自己将边框添加为 TextField 下方的 Sprite。比如:

package
{

import flash.display.Graphics;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

public class TextBorder extends Sprite
{
    private static const CORNER_RADIUS:int = 5;
    // display objects
    private var background:Sprite;
    private var field:TextField;

    // properties
    private var _text:String;

    public function TextBorder()
    {
        background = new Sprite;
        field = new TextField;
        field.autoSize = TextFieldAutoSize.LEFT;

        addChild(background);
        addChild(field);

        // TESTING:
        text = "Hello World";
    }

    public function set text(newText:String):void
    {
        _text = newText;
        display();
    }

    public function get text():String
    {
        return _text;
    }

    private function display():void
    {
        field.text = _text;

        var g:Graphics = background.graphics;
        g.clear();
        g.lineStyle(0, 0x0);
        g.beginFill(0xFFFFFF);
        g.drawRoundRect(0, 0, field.width, field.height, CORNER_RADIUS);
    }
}

}

【讨论】:

  • 感谢您的提示 - 仅测试过一次。我用您的更正更新了代码 sn-p。 FWIW:这是不是生产就绪代码;)
【解决方案2】:

我最终在 Flash 中创建了一个圆角矩形并将其导出为自己的类 -hotspotBG。

var hotspotBackground:hotspotBG = new hotspotBG();
hotspotBackground.width = textField.width + 10;
caption.addChild(hotspotBackground);

【讨论】:

    【解决方案3】:

    您不能自行更改文本字段,自 2014 年起,flash 不允许这样做。

    你可以做的是删除背景和边框, 这将使文本字段完全透明, 然后在文本字段的后面添加一个图像(矩形工具是最简单的方法), 使文本字段位于图像顶部(z 轴方向)

    这可能不是你想象的那样,但它确实有效!

    //you are deleting the background and the borders //and replacing them with an image textbox.background=false; textbox.border=false;

    【讨论】:

      【解决方案4】:

      你可以只使用 CSS 样式吗?比如:

      TextInput { 
        borderStyle: solid; 
        borderThickness: 1; 
        cornerRadius: 2; 
      }
      

      我没有对此进行测试,但这应该会给你一个圆角。

      【讨论】:

      猜你喜欢
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 2013-06-11
      • 2011-02-04
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多