【问题标题】:Cannot get text in TextField to display无法在 TextField 中获取要显示的文本
【发布时间】:2013-07-08 10:53:48
【问题描述】:

我正在尝试在 ActionScript 3 中动态创建 TextField。下面的代码绘制了文本框本身(在本例中只是一个红色矩形),但不显示字符串 "Add text here"。我该怎么做才能解决这个问题?

var d:Number = mc.getNextHighestDepth();

var x:Number = (screenWidth - boxWidth) / 2;
var y:Number = (screenHeight - boxHeight) / 2;

var w:Number = boxWidth;
var h:Number = boxHeight;

notification = mc.createTextField("Text", d, x, y, w, h);
notification.background = true;
notification.backgroundColor = 0xFF0000;
notification.selectable = false;
notification.wordWrap = true;
notification.text = "Add text here";

【问题讨论】:

  • 确保嵌入了为TextField 设置的字体。将TextFormat 对象分配给TextFielddefaultTextFormat 属性,并在更改字体时调用TextFieldsetTextFormat(format) 方法。发布您的 mc.createTextField 方法源也会有所帮助,因为我们无法真正看到您在其中做了什么。正如@Discipol 回答的那样,您还需要将任何类型的DisplayObject 添加到DisplayList 以使其可见,但如果绘制了红色矩形,我假设您已经添加了它。
  • ms.creatyeTextField的出处是什么意思?这是标准的MovieClip.createTextField 方法。
  • 哦,抱歉,我没看出来你实际上在使用 AS2 API,我还以为你有一个 MovieClip 的子类。因此,在 Actionscript 3 中,您不会像那样创建 TextField。在 AS3 中创建TextField 的正确方法如下:var tf:TextField = new TextField(); 然后将其作为子级添加到父级DisplayObjectContainer 并根据需要设置TextFormat

标签: flash actionscript textfield


【解决方案1】:

您需要执行 addChild(notification) 以便将 textField 添加到显示列表中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    相关资源
    最近更新 更多