5 Replies Latest reply on Aug 3, 2009 11:29 AM by Ned Murphy

    string question

    AttaBoy2 Level 3

      in as2 I have this statement:

      if(_level2._url != "file:///C|/Project/slideShow2.swf"){
                  trace("yada yada yo");
                  loadMovieNum("slideShow2.swf", 2);
              }

      This works fine but when I upload to my clients server the url might be somewhat different.  Is there a way to split off the last 14 characters and see if they = slideShow2.swf or is there a command if the string contains "slideShow2.swf". 

        • 1. Re: string question
          Ned Murphy Adobe Community Professional & MVP

          You can use the indexOf() method of the String class to determine if the string is a substring...  -1 is returned if the string is not found

           

          var str1 = "file:///C|/Project/slideShow2.swf";
          var str2 = "Project/slideShow2.swf";
          var str3 = "Project/slidShow2.swf";

           

          trace(str1.indexOf("slideShow2.swf")); // 19
          trace(str2.indexOf("slideShow2.swf")); // 8
          trace(str3.indexOf("slideShow2.swf")); // -1

          1 person found this helpful
          • 2. Re: string question
            AttaBoy2 Level 3

            Thanks for replying Ned.  That wouldn't work for me because I won't know what the index of the first character of my string will be.  If there's a  index of last character then the index would be that char -14.  I'll bet there's a string lenth attribute if I just subtract 14 from that I'll have my indexOf.

            If any other ideas come to mind let me know.  I don't know AS2 very well and didn't realize I'd need to know it someday so I'm scrambling to learn what I need quickly.

            • 3. Re: string question
              AttaBoy2 Level 3

              I got it I just used the .lenth property then subtracted 14.  Thanks for your help.

              • 4. Re: string question
                AttaBoy2 Level 3

                I'm sorry you had the correct answer.   I'm such a dufas.

                • 5. Re: string question
                  Ned Murphy Adobe Community Professional & MVP

                  No, if the indexOf returns anything positive (0+), you know that string is within the string you are testing.  That's all you said you wanted to know.  If you want to know where it is, the indexOf tells you that as well.