Actionscript 3 文本字段未添加到后台

Actionscript 3 文本字段未添加到后台,actionscript-3,flash,actionscript,flash-cs5,Actionscript 3,Flash,Actionscript,Flash Cs5,无法将文本字段添加到舞台 public function create(tot:Number, tot2:Number, xp:Number, yp:Number):void { var txt:TextField = new TextField(); var format:TextFormat = new TextFormat(); format.font = "Verdana";

无法将文本字段添加到舞台

public function create(tot:Number, tot2:Number, xp:Number, yp:Number):void
        {
            var txt:TextField = new TextField();
            var format:TextFormat = new TextFormat();
            format.font = "Verdana";
            format.color = 0xFF0000;
            format.size = 10;
            format.underline = true;
            txt.defaultTextFormat = format;

            if (tot != tot2)
            {
                txt.text = String(tot - tot2);
                txt.x = xp;
                txt.y = yp;
                trace(tot - tot2);
                trace(xp + " + " + yp);
                addChild(txt);
            }
        }
这是主时间线上的代码:

mt.create(rtg.chk(inp.text,dyn.text,Total,str), Total, mouseX, mouseY);
我尝试了stage.addChild(),root,尝试通过MC添加它。真是难住了

trace函数返回我想要的tf中的细节,但它只是不创建


干杯。

看起来不错,因为跟踪与您预期的一样,我会检查mt是否添加到stage,同时尝试跟踪textfield.parent和textfield.stage,看看您得到了什么。听起来您确定满足了您的密码:
如果(tot!=tot2)
因为跟踪语句?你有错误吗?或者只是看不到文本字段?如果在
addChild
之后放置:
trace(txt.parent)
您得到了什么?跟踪parent给我[object MiniDisp],跟踪txt.stage给我null。没有错误,因为跟踪正在运行,所以满足了条件。您是否要将MiniDisp实例添加到显示列表中?似乎没有添加某些父/祖先。跟踪this:parent.stage和this:this.stage。你不能将它添加到stage,因为我打赌你会得到stage=>null。新手错误。将mt添加到主舞台。为大家干杯。