在动作脚本3中定时器等于零时更改场景

时间:2012-01-21 11:35:14

标签: flash actionscript-3

我想在我的计时器等于零时更改场景我该怎么做 请帮帮我。?

import flash.events.TimerEvent;

var count:Number = 100;

var myTimer:Timer = new Timer(300,count);
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.start();

function countdown(event:TimerEvent):void 
{
    myText_txt.text = String((count)-myTimer.currentCount);
}

2 个答案:

答案 0 :(得分:2)

倾听flash.events.TimerEvent.TIMER_COMPLETE事件。

你应该开始使用Actionscript Reference,非常有帮助。

答案 1 :(得分:1)

package  
{
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.utils.Timer;
    /**
     * ...
     * @author Jeet Chauhan
     */
    public class Timertest extends Sprite 
    {
        private var myText_txt:TextField;
        private var count:Number = 100;
        private var myTimer:Timer;

        public function Timertest() 
        {
            init()
        }

        private function init():void 
        {
            //create assets
            myText_txt = new TextField();
            myText_txt.x = 50;
            myText_txt.y = 50;
            myText_txt.width = 300;
            addChild(myText_txt);


            myTimer = new Timer(300,count);
            myTimer.addEventListener(TimerEvent.TIMER, countdown);
            myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, countdownComplete);
            myTimer.start();
        }

        private function countdown(event:TimerEvent):void 
        {
            myText_txt.text = String((count)-myTimer.currentCount);
        }

        private function countdownComplete(e:TimerEvent):void 
        {
            myText_txt.text = "Hurrey timer Complete";
        }

    }

}