Actionscript 3 动作脚本记分板

Actionscript 3 动作脚本记分板,actionscript-3,helper,Actionscript 3,Helper,你好,我是初学者, 我这里有我的AS3代码 package { import flash.text.TextField; import flash.text.TextFormat; import flash.media.Sound; import flash.net.URLRequest; /** * ... * @author Artur */ public class Scoreboard extends Te

你好,我是初学者, 我这里有我的AS3代码

package  
{
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.media.Sound;
    import flash.net.URLRequest;
    /**
     * ...
     * @author Artur
     */
    public class Scoreboard extends TextField
    {
        public var score:int;
        public function Scoreboard() 
        {
            score = 0;
            var txtf:TextFormat = new TextFormat;
            txtf.color = 0xFFCC33;
            txtf.size = 25;
            txtf.font = "verdana";
            txtf.bold = true;
            this.defaultTextFormat = txtf;
            this.text = "Score : 0"
            this.width = 300;
            this.x = 530;
        }
        public function updateScore(_score:int):void 
        {
            score += _score;
            this.text = "Score: " + score;
        }

    }

}
我想改变文本格式的颜色,若分数大于100,它将变为绿色 如果低于0,则为红色

我有这个密码

    if (score>100){
        txtf.color = 0xFFCC33;

} else if (score>50){
        txtf.color = 0xFFCC33;


}
我不知道如何在第一个代码中实现它。 有人能帮我吗

谢谢。

试试这个:

...

public function updateScore(_score:int):void {

    score += _score

    if (score > 100){

        txtf.color = 0x00FF00    // green

    } else if (score < 0){

        txtf.color = 0xFF0000    // red

    }   
    this.setTextFormat(txtf)
    this.text = "Score: " + score

}

...

嗯,想想看。你什么时候会检查当前分数,看看它有多高?我不确定,我想我需要使用addEventListener来检查它。我现在在学校用AC3编程两周了,在空闲时间,但我对这方面不太了解。事实上,解决方案要简单得多。当你改变分数时,你应该检查分数。代码中唯一可以更改分数的部分是函数
updateScore(int)
。正如Akmozo在他的回答中指出的那样,您应该在类的构造函数之外声明
txtf
。谢谢,我收到了错误:C(33):col:9错误:访问未定义的属性txtf。txtf.color=0x00FF00//绿色^C:):列:9错误:访问未定义的属性txtf。txtf.color=0xFF0000//red^(40):列:24错误:访问未定义的属性txtf。这个.setTextFormat(txtf)^Build因错误而停止(fcsh)。呃,我再也不明白了。你的意思是你得到了你想要的吗?
...

private var txtf:TextFormat

public function Scoreboard() {

    ...        

    txtf = new TextFormat()

    ....

}

...