Skip to main content
Known Participant
November 21, 2007
Question

Action IF THEN statement help needed.

  • November 21, 2007
  • 4 replies
  • 238 views
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:

This topic has been closed for replies.

4 replies

Participating Frequently
November 22, 2007
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;
Inspiring
November 21, 2007
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);
}
kovacicAuthor
Known Participant
November 21, 2007
Im sorry for being newb, but how can I incorperate this into an IF statement?

Inspiring
November 21, 2007

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);