4 Replies Latest reply on Sep 3, 2007 2:24 AM by adreny

    how to used replaceText?

    adreny Level 1
      var word:String = "Hi, My name is <a>leon</a> lee.";

      anyone can told me how to used replaceText function to replace <a> and </a> to become ""
        • 1. Re: how to used replaceText?
          kglad Adobe Community Professional & MVP
          is this as3 and you want to use the replace() method of strings?
          • 2. Re: how to used replaceText?
            adreny Level 1
            hi, kglad
            i m using AS2 , i can done this by the following action script already

            replace = msg.split("<a>").join("");
            finalReplace = replace.split("</a>").join("");

            but dun know why can only replace the 1st part of text that contain <a>hi</a>
            the second one <a>james</a> still remain there, if my text define like following this ....
            <a>hi</a>,my name is <a>james</a>.
            • 3. Re: how to used replaceText?
              Greg Dove Level 4
              No, it works as intended.

              You can view it working like this:

              var msg="<a>hi</a>,my name is <a>james</a>."
              trace("msg is:"+msg)
              replace = msg.split("<a>").join("");
              trace("replace is:"+replace)
              finalReplace = replace.split("</a>").join("");
              trace("finalReplace is:"+finalReplace)
              • 4. Re: how to used replaceText?
                adreny Level 1
                you are right GWD. i m see wrong error. the function is work properly.
                the problem actually is ...

                var myOtherFormat = new TextFormat ();
                myOtherFormat.color = 0x006699;

                startOfWord = msg.indexOf("<a>") ;
                endOfWord = msg.indexOf("</a>") ;

                imsg.html = false;
                imsg.text = finalReplace;
                imsg.autoSize = "center";
                imsg.setTextFormat (startOfWord,endOfWord-3,myOtherFormat);

                the style format does not apply to the second <a>james</a>