Eventlisteners for UI elements?


    Oct 15 2012 | 12:43 pm
    Is there a way to call a function when the value of a ui element changes?

    • Oct 16 2012 | 11:40 am
      did u find out already ? ... perhaps you can compare an incoming event with the last one (stored) and then execute the function . I cant check it on my own at the moment
    • Oct 24 2012 | 12:57 am
      It would be cool to have an onChange listener for outlets of a Maxobj and the Maxobj should know its outlet count. The workaround could be to connect a (hidden) js to the element... something like this
      autowatch = 1;
      function loadbang(){ args = arrayfromargs(messagename,arguments); anything(args); }
      function bang(){ args = arrayfromargs(messagename,arguments); anything(args); }
      function msg_int(){ args = arrayfromargs(messagename,arguments); anything(args); }
      function msg_float(){ args = arrayfromargs(messagename,arguments); anything(args); }
      function list(){ args = arrayfromargs(messagename,arguments); anything(args); }
      function anything(args){ if(typeof(args) == 'undefined'){ args = arrayfromargs(messagename,arguments); } outletListener.changed(args);
      //post("anything "+args.toSource()+"n"); } //OutletListener.local = 1; OutletListener = function(){ this.oldVal; this.callbacks = new Array(); this.add = function(callback){ this.callbacks.push(callback); }
      this.changed = function(args){ for(index in this.callbacks){ if(typeof(this.callbacks[index] == 'function')){ var tmp = false; if(typeof(this.oldVal) != 'undefined'){ tmp = this.oldVal; } this.oldVal = args; this.callbacks[index].call(this, tmp, args); //post("changed " + args.toSource()+"n"); } } }
      this.onChange = function(oldVal, newVal){ post("onChange oldVal: " + oldVal.toSource() + " newVal: " + newVal.toSource()+"n"); }
      this.add(this.onChange); return this; }
      outletListener = new OutletListener();