0

我正在尝试进行计时器倒计时,我相信我拥有所有的碎片,每当我测试它时,它都会一直给我这个错误。

知道发生了什么吗?

package 

{
    import flash.display.MovieClip;
    import flash.events.TimerEvent;
    import flash.utils.Timer;

    public class MainTimer extends MovieClip {
        private var currentMin:int;
        private var currentSec:int;

        private var oneSecondTimer:Timer = new Timer (1000,1);
        public var timeHasStopped:Boolean=false;

        public function MainTimer() {
        // constructor code
            trace("the main timer is here");
            currentMin = 2;
            currentSec = 5;

            minBox.text = String(currentMin);

            if(currentSec < 10)
            {
                secBox.text = "0" + String(currentSec);
            }
            else {
                secBox.text = String(currentSec);
            }

            oneSecondTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
            oneSecondTimer.start();

            private function onTimerComplete(event:TimerEvent):void {
                currentSec = currentSec -1;
                if(currentSec <0) 
                    {
                        currentSec =59;
                        currentMin -=1;
                    } //end if
                if(currentMin < 0) {
                        currentMin =0;
                        currentSec =0;
                        timerHasStopped = true;
                }
                else 
                    {
                        oneSecondTimer.start();
                    }
                minBox.text =String(currentMin);
                secBox.text =String(currentSec);

                if(currentSec <10) 
                    {
                        secBox.text = "0" + String(currentSec);
                    }
            }
    } // Ends Function

} // Ends Class

} // Ends Package
4

2 回答 2

1

函数onTimerComplete在函数内部MainTimer;它不是类成员,因此该private关键字不适用。

于 2016-05-18T23:21:28.307 回答
1

函数必须有左{大括号,并且必须用 a 关闭,}然后才能创建另一个新函数。您} // Ends Function应该放在该行之后oneSecondTimer.start();,从那里开始您可以定义其他第二个功能function onTimerComplete

如果您缩进代码可能会有所帮助,以便您可以轻松查看事情的开始和结束位置(使用TAB键)。

您的缩进代码示例如下(已删除文本),看看这种结构如何更容易看到大括号并因此发现任何缺失或多余的大括号?

public function MainTimer() 
{
    // constructor code

    .......

    if(currentSec < 10)
    {
        .......
    }
    else 
    {
        .......
    }

    .......

} //Ends function called MainTimer

private function onTimerComplete(event:TimerEvent):void 
{
    .......

    if(currentSec <0) 
    {
        .......
    } //end if
    if(currentMin < 0) 
    {
        .......
    }
    else 
    {
        .......
    }

    .......

    if(currentSec <10) 
    {
        .......
    }
} //Ends function called onTimerComplete
于 2016-05-19T04:41:50.867 回答