4 Replies Latest reply on Mar 2, 2007 6:29 AM by kglad

    Selection.getBeginIndex()???

    Level 7
      Is there not anyone who can get this to work?
      If someone could point me to a working example of selecting a word in an
      input field, and then replacing that word with something else, via a button
      press, I'd sure appreciate it. All my attempts at this have failed.

      --
      Dave -
      Head Developer
      www.blurredistinction.com
      Adobe Community Expert
      http://www.adobe.com/communities/experts/


        • 1. Re: Selection.getBeginIndex()???
          Level 7
          My solution is kinda ugly, but it works okay I guess. Have your input
          textfields, and a button with instance name "btn"

          keepTrackID = setInterval(function(){
          var f = eval(Selection.getFocus());
          if(f != null){
          b = Selection.getBeginIndex();
          e = Selection.getEndIndex();
          }
          },10);
          btn.onSetFocus = function(oldFocus,newFocus){
          this.onPress = function(){
          this.onPress = function(){};
          var t = 'hello there!';
          oldFocus.replaceText(b,e,t);
          clearTimeout(this.id);
          var obj = {b:b,e:b+t.length,o:oldFocus};

          this.id2 = setInterval(function(){
          while(Selection.getBeginIndex()!=obj.b &&
          Selection.getEndIndex()!=obj.e){
          Selection.setFocus(obj.o);
          Selection.setSelection(obj.b,obj.e);
          }},1);
          this.onMouseUp = function(){
          clearInterval(this.id2);
          delete this.onMouseUp;
          }
          }
          this.id = setTimeout(function(){btn.onPress =
          function(){};b=null;e=null},0);
          }
          Selection.addListener(btn);


          "DMennenoh **AdobeCommunityExpert**" <dave@blurredistinction.com> wrote in
          message news:erv5v4$p3k$1@forums.macromedia.com...
          > Is there not anyone who can get this to work?
          > If someone could point me to a working example of selecting a word in an
          > input field, and then replacing that word with something else, via a
          > button press, I'd sure appreciate it. All my attempts at this have failed.
          >
          > --
          > Dave -
          > Head Developer
          > www.blurredistinction.com
          > Adobe Community Expert
          > http://www.adobe.com/communities/experts/
          >


          • 2. Re: Selection.getBeginIndex()???
            kglad Adobe Community Professional & MVP
            try this one, too. if your textfield has instance name tf:

            • 3. Re: Selection.getBeginIndex()???
              Level 7
              Ah Ha! Thanks much to the both of you! kglad's method was just what I
              needed - getting the indexes in a mouseUp attached to the root. Seems so
              easy now - just like it should have been.

              --
              Dave -
              Head Developer
              www.blurredistinction.com
              Adobe Community Expert
              http://www.adobe.com/communities/experts/


              • 4. Re: Selection.getBeginIndex()???
                kglad Adobe Community Professional & MVP
                you're welcome.