Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 看到每一个分数_Actionscript 3 - Fatal编程技术网

Actionscript 3 看到每一个分数

Actionscript 3 看到每一个分数,actionscript-3,Actionscript 3,我最近开始编程,在分数显示方面遇到了一个问题。分数递增和显示没有问题,只是分数更新时不会删除最后一个分数。经过十几帧之后,我看到了一堆乱七八糟的分数。我花了几天时间在谷歌上搜索,看看是否能找到任何类型的答案,但没有发现类似的问题 我的代码: public function balldistance(event:Event){ // function called on ENTER_FRAME in order to update the distance of the ball obj

我最近开始编程,在分数显示方面遇到了一个问题。分数递增和显示没有问题,只是分数更新时不会删除最后一个分数。经过十几帧之后,我看到了一堆乱七八糟的分数。我花了几天时间在谷歌上搜索,看看是否能找到任何类型的答案,但没有发现类似的问题

我的代码:

public function  balldistance(event:Event){ // function called on ENTER_FRAME in order     to update the distance of the ball object

var txt:TextField = new TextField(); 
txt.text = "Distance:  " + String(balldist);
txt.x = 25;
txt.y = 25;
addChild(txt);

trace(balldist);  // I added this line in my code for troubleshooting purposes just so    I could see the balldist augment.
balldist += Ball5.dx;  // I am having the score(balldist) augment based on the distance the ball has traveled from its starting point.
}
我的一个朋友建议使用RemoveChildText,但当我尝试使用它时,它没有显示分数更新


谢谢

每次触发ENTER_FRAME时,您都会创建一个新的txt:TextField

尝试在侦听器函数之外声明/初始化它一次:

var txt:TextField = new TextField(); 
txt.x = 25;
txt.y = 25;
addChild(txt);
然后在输入帧引用时,输入相同的txt TextFeild实例,而不是一次又一次地创建新实例:

public function  balldistance(event:Event){
  txt.text = "Distance:  " + String(balldist);
  balldist += Ball5.dx;
}

非常感谢你!在添加了更改之后,我不再有这个问题。