倒计时器在AS3中不起作用

时间:2014-03-18 16:17:17

标签: actionscript-3

因为我是AS3中的新手而我刚刚将AS2转换为AS3。倒计时不起作用。现在4位数字在同一时间非常快地循环(三位数动画很好 - 忽略它)

请参阅倒计时 - http://magnixsolutions.com/clients/OT/media-buys_scoreboard-redux_160x600_5-8-2009.html

AS3

// get the current date and time as it exists at
// this instance in time when the frame is entered
var currentDate:Date = new Date();
var thisYear:int = currentDate.getFullYear();
var thisMonth:int = currentDate.getMonth();
var thisDate:int = currentDate.getDate();
var thisHour:int = currentDate.getHours();
var thisMinute:int = currentDate.getMinutes();
var thisSecond:int = currentDate.getSeconds() + 12;
var thisMSecond:int = currentDate.getMilliseconds();

// Date( year, month-1, date [, hour [, minute [, second [, millisecond]]]])
var eventDate = new Date(thisYear, thisMonth, thisDate, thisHour, thisMinute,        thisSecond, thisMSecond);
var eventMillisecs = eventDate.getTime();

// get the current date and time as it exists at
// this instance in time when the frame is entered
this.addEventListener(TimerEvent.TIMER, enterFrameHandler);
function enterFrameHandler() {
currentDate = new Date();
var currentMillisecs = currentDate.getTime();

this.msecs = eventMillisecs - currentMillisecs;

if (this.msecs <= 0){
    play();
    return;
}

// if the date hasn't been reached, continue to
// devise seconds, minutes, hours and days from
// the calculated milliseconds
this.secs = Math.floor(this.msecs/1000); // 1000 milliseconds make a second
this.mins = Math.floor(this.secs/60); // 60 seconds make a minute
this.hours = Math.floor(this.mins/60); // 60 minutes make a hour
this.days = Math.floor(this.hours/24); // 24 hours make a second

this.msecs = int(this.msecs % 1000);
this.secs = int(this.secs % 60);
this.mins = int(this.mins % 60);
this.hours = int(this.hours % 24);
this.days = int(this.days);

while (this.msecs.length < 3) this.msecs = "0" + this.msecs;
if (this.secs.length < 2) this.secs = "0" + this.secs;
if (this.mins.length < 2) this.mins = "0" + this.mins;
if (this.hours.length < 2) this.hours = "0" + this.hours;
while (this.days.length < 3) this.days = "0" + this.days;

for(var movie in this){
    if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this); 
}
};

MovieClip.prototype.evaluateFrameFrom = function(variableClip){
var nameArray = this._name.split("_");
var numberSet = variableClip[nameArray[0]];
var character:int = parseInt(nameArray[1]);
    var frame = 1 + parseInt(numberSet.charAt(character));
if (this._currentframe != frame) this.gotoAndStop(frame);
};

1 个答案:

答案 0 :(得分:1)

这可能是你的意思:

// There is no number type in AS3. Use parseInt to cast string to int
var character:int = parseInt(nameArray[1]);
var frame = 1 + parseInt(numberSet.charAt(character));

此外,ActionScript 3.0中没有_root这样的东西。试试这个:

this.avgscore_mc.gotoAndPlay(2);

你需要像这样添加你的enterFrame:

this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

function enterFrameHandler() {
    // Stuff in your enter frame
}

听起来你还在想AS 2.0!