0

So as not to complicate my question, I won't involve the context, but basically let's say I have a variable:

var foo:int;

And 'foo' is constantly incrementing, how would I be able to perform a function every 300 increments (300,600,900, etc) of 'foo'?

Cheers

EDIT: Also worth mentioning, the number can occasionally skip numbers as it is a rounded version of a decimal number that is incrementing

4

1 回答 1

0

将其设为私有变量并仅使用这些访问器方法访问它怎么样:

function getFoo():int {
    return foo;
}

function setFoo(newFoo:int):void {
    if (newFoo % 300 > foo % 300) performAction();
    foo = newFoo;
}

当然,您也可以添加方便的方法incrementFoo(increment:int)

对于可能的语法错误,我们深表歉意。好久没用AS3了。

于 2013-05-12T19:01:35.177 回答