0

对于某些人来说,这确实是一个容易回答的问题,呵呵:每次进入特定框架时,​​如何将变量值增加 1?

我目前有这段代码运行一次,然后下次时间轴在帧上时它不会再次运行:

// This is at the end of the animation

var DAY = 0;

DAY++;
dayTextField.text = DAY;

gotoAndStop(7); // Go to the beginning and re-loop the animation

我曾尝试在从 a 运行的函数中执行此代码stage.addEventListener(Event.ENTER_FRAME, function),但这只会一遍又一遍地不停地增加值。

谢谢你。

4

1 回答 1

0

出于某种奇怪的原因,我让它工作了。这段代码是在开头添加的,而不是像我上次那样在结尾添加。这是我所做的:

var DAY = 0;

stage.addEventListener(Event.ENTER_FRAME, newDayFunc);

function newDayFunc(event:Event) {
    if (currentFrame == 1286) {
        if (Moon.hitTestObject(wallNewDay)) {
            DAY++;
            dayTextField.text = DAY;
            trace("What day it is:", DAY);
        }
    }
}

**这是我在弄清楚一些事情后最终使用的,呵呵:

// I figured it out. This is on the last frame.

// Variables
var DAY = 0;
//
// Listeners
stage.addEventListener(Event.ENTER_FRAME, newDayFunc);
//
// Functions
function newDayFunc(event:Event) {
        if (DAY < 7)) {
            DAY++;
            dayTextField.text = DAY;
            trace("What day it is:", DAY);
            stage.removeEventListener(Event.ENTER_FRAME, newDayFunc);
        } else {
            // Added other eventListeners that needed to be removed
            gotoAndStop("finished"); // The name of the finish frame
        }
}
//
于 2013-09-29T17:06:45.573 回答