Is there a way to check if an integer will be higher or lower in AS3

I am trying to make a script that listens to a variable (int or Number) and then performs certain functions, whether the variable is above or below. So, for example, if the number gets higher, it performs one function. If it gets lower, it starts another one.

Is this possible in AS3? Any ideas?

+2


a source to share


3 answers


Use a private variable with an installer. In the setter, compare the previous value with the current value:



private var _num:Number = 0;

public function set num(value:Number) : void {
  if (value < _num) {
    //do something if it lower
  } else if (value > _num) {
    //do something if it higher
  } else {
    // do something if it equal
  }
  _num = value;
}

      

+7


a source


Store the int, then set the event to fire at the speed you want. In the event listener callback, check if the current int is higher or less than the stored int, handle what you need, and update the stored int.
This is probably not the best practice.



0


a source


If you have no control over the source so that you can change the installer, you can use ChangeWatcher.watch ().

0


a source







All Articles