AS3 圆角文本字段

发布于 2024-07-29 19:09:55 字数 362 浏览 2 评论 0原文

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

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

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

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

Does anyone know how to create a dynamic textfield with a visible border and rounded corners in AS3?

I think I might have to create a rounded movieclip, resize and place it behind the text.

I tried this, but I don't see any changes.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

抱猫软卧 2024-08-05 19:09:55

以下是ActionScript 3 中 TextField 的可用 CSS 样式的列表< /a>. 抱歉,没有圆角半径。

您可以在 TextField 对象上打开文本字段的边框 边界属性。 但附近没有可用的房产。

我建议您创建一个新组件,并自行将边框添加为 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);
    }
}

}

Here is a list of the available CSS styles for TextFields in ActionScript 3. Sorry, there is no corner radius.

You can turn on a border for a textfield on the TextField objects border property. But there is not a property available to round the corner.

I suggest you create a new component and add the border yourself as a Sprite underneath the TextField. Something like:

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

}
翻了热茶 2024-08-05 19:09:55

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

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

I ended up creating a rounded rectangle in flash and exporting it as its own class - hotspotBG.

var hotspotBackground:hotspotBG = new hotspotBG();
hotspotBackground.width = textField.width + 10;
caption.addChild(hotspotBackground);
抱猫软卧 2024-08-05 19:09:55

您无法自行更改文本字段,截至 2014 年,Flash 不允许这样做。

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

这可能不是您想到的方式,但它确实有效!

//您正在删除背景和边框
//并用图像替换它们
文本框.背景=假;
textbox.border=false;

You cannot change the text field it self, as of 2014 flash does not allow that.

What you can do is delete the background and the borders,
which will leave the text field completely transparent,
then add an image (rectangle tool is the easiest way to do this) at back of the text field,
so that the text field is on top of the image (z-axis-wise)

It may not be the way you thought of but hell it works!

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

深巷少女 2024-08-05 19:09:55

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

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

我还没有测试过这个,但这应该会给你一个圆角。

Can you just use the CSS styles? Something like:

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

I haven't tested this, but that should give you a rounded corner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文