3 Replies Latest reply on Oct 30, 2009 12:46 PM by kglad

    Actionscript for: If (text has been changed) {do something...

    Andymc7 Level 1

      Well, my title says it all. What is some Actionscript I can use so that an event can occur only if a dynamic text box has been changed? I've used the onChange event, but I'm not sure how to use it in some logic. Ideas?

       

      Thanks for any help

        • 1. Re: Actionscript for: If (text has been changed) {do something...
          Rothrock Level 5

          The onChanged event only happens when the text is changed, so there really isn't a need for any logic. Of course a change can be the addtion of a space and then removing a space is another change. The end result looks exactly like the original.

           

          And if you need to do something else if the text isn't changed then you need a whole different approach.

           

          You might want to look into onSetFocus and onKillFocus which would allow you to track how a field started and how it finished.

           

          Without knowing exactly what you are trying to do it is hard to give more specific advice.

          • 2. Re: Actionscript for: If (text has been changed) {do something...
            Andymc7 Level 1

            Thanks for the quick reply, and sorry I wasn't more specific.

             

            What I want to do is enable a button, but only after two separate textfields have been changed. So, I know I can use onChanged() for one textfield to enable the button, but that doesn't get me the desired result. Basically, I don't want the button to be operable unless both text fields have been changed. I know I'm being a little repetitive. Hope this makes sense.

            • 3. Re: Actionscript for: If (text has been changed) {do something...
              kglad Adobe Community Professional & MVP

              if tf1 and tf2 are your textfield instance names, you can use:

               

              var n:Number = 0;
              var tfNum:Number = 2;

               

              for (var i:Number=1; i<=tfNum; i++) {
                  this["tf"+i].onChanged = f
              }

               

              function f(){
                  i = this._name.substr(2);
                  n = Math.max(n,n ^ (1 << i));
                  if(n==Math.pow(2,tfNum+1)-2){
                      //enable your btn

                  // and null your onChanged methods
                  }
              }