actionscript-3 - as3 文本字段占位符

标签 actionscript-3

我有一个关于 as3 上的文本字段占位符的快速问题。

所有现代浏览器或移动应用程序都支持文本输入字段的占位符。单击它后,焦点将移动到文本的开头,占位符将一直保留到您开始键入为止。

只是想知道这是否可以在 as3 上实现?

干杯 账单

最佳答案

当然可以,但是您需要手动对该 TextField 执行一些操作。一般例程是这样的:有一个 TextField 后代类,它将有一个字段来保存占位符文本。

一个例子:

public class PlaceholderTF extends TextField
{
    private var placeholderText:String;
    private var currentText:String;

    public function PlaceholderTF(prompt:String="Input text here") {
        super(); // making a correct TextField out of ourselves
        placeholderText = prompt;
        currentText = "";
        AWUTA = false;
        text = "";
    }

    public override function set text(value:String):void {
        if (currentText != value) {
            currentText = value;

            // calling built-in setter to correctly update text
            if (currentText == null || currentText == "") {
                super.text = placeholderText;
            } else {
                super.text = currentText;
            }
        }
    }
}

这个解决方案非常粗糙,但可能会奏效。

关于actionscript-3 - as3 文本字段占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13225942/

相关文章:

actionscript-3 - 嵌入欧美字符

actionscript-3 - 将加载的 swf 与使用父级隔离

api - 在 action=track leanplum Rest Api 中发送字符串参数不工作

actionscript-3 - Flex 4.5,如何创建通用换肤库并动态更改 AIR 应用程序的主题?

actionscript-3 - 在AS3中更改宽度和高度后MovieClip消失

actionscript-3 - ActionScript 冲突 : solving exceptions and strange cases

regex - 如何替换字符串中子字符串的所有实例

php - Flex、php 的 MySQL 查询问题

actionscript-3 - 对象主时间轴,对象舞台和as3中的root有什么区别?

javascript - 如何在Flash CS5.5 Actionscript 3.0中创建警报弹出窗口?