lundi 30 janvier 2017

AS file for begin from different frame

I have a timer code.I wanna start of new timer when player has choosing start at specific frame(level).I write AS,I make search for using event listener on package but I can't figure out to how translate that from to class code.

This is orginal code

var minute:Number = 0;
var second:Number = 16;
 
//This timer check to timer and set to what happen if time over.
var timercheck:Timer = new Timer(1000,0);
timercheck.addEventListener(TimerEvent.TIMER, timercheck1);
timercheck.start();
 
function timercheck1(evt:TimerEvent):void {
if (minute <1 && second <1)
{
timer.stop();
timeisup.visible = true;
timeisup.play();
} 
 
}
timeisup.visible = false;
// Create the timer
// Checks the clock function every 1000 milisecond (1 second)
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, clock);
timer.start();
 
// Function that increments the timer

function clock(evt:TimerEvent):void {

// every time this function is checked increment second by one
second -= 1;
 
// If the second is 59
if(second < 0){
// The minute will be plussed with 1
minute -= 1;
//and the zero will be set to 00
second = 59;
}
 
var time:String = minute + ":" + prependZero(second);
sctuts.text = time;
}
 
function prependZero(num)
{
if(num<10)
{
num="0"+num; //Add zero to second if less than 10
}
return(num);
}

And I writing as but I'm not sure goes correct.

package  {
 import flash.utils.Timer;
 import flash.events.TimerEvent;

public class timertick {

    static public var minute:Number = 2;

    static public var second:Number = 0;

    static public var timercheck:Timer = new Timer(1000,0);

    static public var timer:Timer = new Timer(1000);

    static public var time:String = minute + ":" + prependZero(second);

    public function timercheckbasla():void {
        timercheck1 = new Timer(1000,0);
        timercheck1.addEventListener(TimerEvent.TIMER, onTimer);
        timercheck.start();
    }

    // Create the timer
    // Checks the clock function every 1000 milisecond (1 second)
    public function timer():void {
        timercheck1 = new Timer(1000,0);
        timercheck1.addEventListener(TimerEvent.TIMER, onTimer);
        timercheck.start();
    }


    private function onTimer(e:TimerEvent):void {

            if (minute <1 && second <1)
{
timer.stop();
timeisup.visible = true;
timeisup.play();
} 
 
//I not finished yet

    }

}
}

Aucun commentaire:

Enregistrer un commentaire