var now:int = 0;
var thn:int = 0;
function loop():void
{
// Change the number.
now = changingNumber;
if(now > thn)
{
trace("Got larger.");
}
else if(now < thn)
{
trace("Got smaller.");
}
else
{
trace("Maintained value.");
}
// Store the changed value for comparison on new loop() call.
// Notice how we do this AFTER 'now' has changed and we've compared it.
thn = now;
}
または、自分の価値に合わせてゲッターとセッターを準備し、そこで増減を管理することもできます。
// Properties.
var _now:int = 0;
var _thn:int = 0;
// Return the value of now.
function get now():int
{
return _now;
}
// Set a new value for now and determine if it's higher or lower.
function set now(value:int):void
{
_now = value;
// Comparison statements here as per above.
// ...
_thn = _now;
}
この方法はより効率的で、ループを必要としません。