4 Replies Latest reply on Nov 21, 2007 11:35 PM by ggshow

    Action IF THEN statement help needed.

    kovacic
      I am working on a simple reply bot for the holidays, and I am having trouble with some IF THEN statements.. I have attached the code as so far.

      I am looking to be able to have the script look for certain words in the user text field, and reply accordingly. I understand this uses the indexOf command, but I am not yet skilled enough to use it.

      It would be a HUGE help if anyone could shed some light on the subject.. Thanks in advance!!!

      Here is what I have so far:

        • 1. Re: Action IF THEN statement help needed.
          Greg Dove Level 4

          to check the presence of a string
          var str1="needle";

          inside another string

          var str2="haystack, haystack, needle & more haystacks";

          indexOf returns the position of needle inside haystack, like this:

          var foundPosition = str2.indexOf(str1);

          If str1 is not found inside str2 then foundPosition is equal to -1;

          so to check if needle is inside haystack (anywhere at all) then all you need to do is :

          var foundInside:Boolean = (str2.indexOf(str1)!=-1);

          • 2. Re: Action IF THEN statement help needed.
            kovacic Level 1
            Im sorry for being newb, but how can I incorperate this into an IF statement?

            • 3. Re: Action IF THEN statement help needed.
              Greg Dove Level 4
              here's an example. Try it in flash and change the string values until you're confident how it works.

              var str1:String="needle";
              var str2:String="haystack haystack haystack needle haystack";
              //if statement example:
              if (str2.indexOf(str1)!=-1) {
              trace("string:"+str1+" was found inside :"+str2);
              } else {
              trace("string:"+str1+" was not found inside :"+str2);
              }
              • 4. Re: Action IF THEN statement help needed.
                ggshow Level 2
                1) make sure "user" and "reply" are the instance name of your text field, but not the variable name, and it is not TextInput or TextArea component instance.

                2) make sure both "user" and "reply" text field located on your movie root

                3) check case sensitive in your script, .htmlText not .htmltext

                4) make sure you have your "reply" text field html enabled.
                _root.reply.html = true;