actionscript-3 - AS3 圆角文本字段

标签 actionscript-3 dynamic textfield rounded-corners

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

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

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

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

最佳答案

这是 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);
    }
}

}

关于actionscript-3 - AS3 圆角文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1223606/

相关文章:

C++ 多维数组错误的多余代码

cocoa - ALT+ENTER,如何检测NSString中的换行符?

css - Bootstrap 输入组插件未垂直对齐

textfield - 当用户点击字段时,如何将 textFieldStyle 切换为 TextField?

flash - 5000 : The class '..' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type

css - AS3 的 CSS 标识符中的错误?

function - 如何在 Rust 中动态构建具有不同数量参数的函数调用?

flash - 将对象置于前面,在 Flash AS3 中

actionscript-3 - AS3 Air Desktop - 从 ApplicationStorageDirectory 中的 SWF 调度自定义事件

android - 如何更改应用程序的内容