我的动作脚本没有运行我的fla文件

时间:2014-11-18 16:02:40

标签: actionscript-3 actionscript

我的动作脚本没有运行我的fla文件我有一切正确的编码为我的主要编码器,但我的fla文件中的计时器不会倒计时,由于某种原因每次我测试它什么都不做。请帮忙解决问题

package  {

import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
//import flash.events.ThrottleEvent;

public class MainTimer extends MovieClip {

    private var currentMin:int;
    private var currentSec:int;

    private var oneSecondTimer:Timer = new Timer(1000);
    public var timerHasStopped: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); //concatentate with leading zero
        }else{
        secBox.text = String(currentSec);
    }
    oneSecondTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);     
    oneSecondTimer.start();
  }//end function

    private function onTimerComplete(event:TimerEvent):void{

        currentSec = currentSec - 1;
        if (currentSec < 0){
            currentSec = 59;
            currentMin = currentMin - 1;
         }//end if
         if (currentMin < 0){
             currentMin = 0;
             currentSec = 0;
         }else{
             oneSecondTimer.start(); 
         }//end else
         //update display
        minBox.text = String(currentMin);
        secBox.text = String(currentSec);
        if(currentSec < 10){
            secBox.text = "0" + String(currentSec);
        }//end if

    }//end function

}}

1 个答案:

答案 0 :(得分:0)

您必须确保您的班级MainTimer与您的文档相关联。此外,您必须在创建后使用addChild()将元素添加到舞台。