1 Reply Latest reply on Aug 17, 2010 12:30 AM by Subeesh Arakkan

    Is it possible to use startsWith mechanism in ActionScript3.0

    kiran7881 Level 1

      Is it possible to use startsWith mechanism in ActionScript3.0
      Typically i need something like this ,

       

       

      On to change method of the TextInput i need to do this :

       

      function reciveChange():void
      {

      if(myTextIp.text.startsWith("Ra"))

      // do something

      }

       

      Is this possible ??

       

      Thanks in advance .

        • 1. Re: Is it possible to use startsWith mechanism in ActionScript3.0
          Subeesh Arakkan Level 4

          Hi,

           

          You can use the search method of the string class.

           

          function reciveChange():void
          {

               if(myTextIp.text.search("Ra") == 0)

               {

                    // do something

               }

          }

           

           

          Here is the description about search from the docs

           

          String.search(p:*=null):int
          Searches for the specifed pattern and returns the index of the  first matching substring. If there is no matching substring, the method returns  -1.
          Parameters:
          pattern The pattern to match, which  can be any type of object but is typically either a string or a regular  expression.. If the pattern is not a regular expression or a  string, then the method converts it to a string before executing. Note that if  you specify a regular expression, the method ignores the global flag ("g") of  the regular expression, and it ignores the lastIndex property of  the regular expression (and leaves it unmodified). If you pass an undefined  value (or no value), the method returns -1.
          Returns:
          The index of the first matching substring, or -1 if there is no  match. Note that the string is zero-indexed; the first character of the string  is at index 0, the last is at string.length - 1.